Possible Duplicate:
how to parse date in java?
I am getting "Mon Aug 01 00:00:00 IST 2011
" (java.lang.String) as string and i need to convert it to "01-08-2011
" Date(java.Util.Date) ,how to do this
Possible Duplicate:
how to parse date in java?
I am getting "Mon Aug 01 00:00:00 IST 2011
" (java.lang.String) as string and i need to convert it to "01-08-2011
" Date(java.Util.Date) ,how to do this
use the SimpleDateFormat class
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
to print the date. This will print the current date in predefined formatted using SimpleDateFormat
System.out.println("Current Date " + sdf.format(new Date());
String mydate = "01-08-2011";
to convert string into date
Date parseDate = sdf.parse(mydate);
Look at the SimpleDateFormat
class in the javadocs.
Constructs a SimpleDateFormat using the given pattern and the default date format symbols for the default locale
SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
System.out.println("Date " + sdf.format(new Date());