본문 바로가기

안드로이드

[java] 특정일로 부터 7일전 날짜구하기

반응형

특정일로 부터 7일전 날짜구하기


private String get7DayAgoDate(int year , int month , int day) {

Calendar cal = Calendar

.getInstance();

cal.set(year, month-1, day);

cal.add(Calendar.DATE, -7);

java.util.Date weekago = cal.getTime();

SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd",

Locale.getDefault());

return formatter.format(weekago);

}


특정일이 그달의 몇주차 인지 구하기


private String getWeekofMonth(int year , int month , int day){

String tWeek="";

Calendar cal = Calendar

.getInstance();

cal.set(year, month-1, day);

tWeek = Integer.toString(cal.get(Calendar.WEEK_OF_MONTH));

return tWeek;

}


현재날짜 구하기

SimpleDateFormat mSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd",

Locale.KOREA);

Date currentTime = new Date();

date = mSimpleDateFormat.format(currentTime);

반응형

'안드로이드' 카테고리의 다른 글

andrid DB 예제  (0) 2013.11.28
android 주소로 위도,경도얻기  (0) 2013.11.22
안드로이드 트위터 연동  (0) 2013.08.22
안드로이드 카카오스토리 연동  (0) 2013.08.22
안드로이드 네이버 밴드 연동  (0) 2013.08.22