Friday, May 21, 2010

Get CurrentDate in YYYY_MM_DD Format

/**
* Here get the current date in format 'YYYY-MM-DD'
*
* @return Current date in format 'YYYY-MM-DD'
*/
public static String getCurrentDate_YYYY_MM_DD() {
// get current date in Format YYYY-MM-DD
Calendar cal = Calendar.getInstance(TimeZone.getDefault());
final String dateFormat = "yyyy-MM-dd";
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(dateFormat);
sdf.setTimeZone(TimeZone.getDefault());
System.out.println("debug "+sdf.format(cal.getTime()));
return sdf.format(cal.getTime());
}

No comments:

Post a Comment