javawaveblogs-20

Tuesday, March 3, 2009

Java method to format the current date to yyyy-MM-dd using SimpleDateFormat.


/**
* This method will format the current date to yyyy-MM-dd.
* @return
* current date as String.
*/
public static String formatedCurrentDate()
{
String toDate = new Date().toString();
SimpleDateFormat formatter = new SimpleDateFormat(
"EEE MMM yyyy hh:mm:ss zzz");
Date date = formatter.parse(toDate,
new ParsePosition(0));

toDate = new SimpleDateFormat("yyyy-MM-dd").format(date);
return toDate;
}

No comments:

diggthis