| Author |
Example of convert String to Date
|
Kumar Naidu
Greenhorn
Joined: Jul 27, 2006
Posts: 11
|
|
Hi all i have some Problem covert String to Date i am sending My code also. Date currentDatetime = new Date(System.currentTimeMillis()); SimpleDateFormat formatter1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss aaa"); String myDate = formatter1.format(currentDatetime); System.out.println(myDate); Date ss =formatter1.parse(myDate); System.out.println(ss); O/p: 2006-09-04 11:41:07 AM Mon Sep 04 11:41:07 GMT+05:30 2006 (I want same Format in Date Type also yyyy-MM-dd HH:mm:ss aaa"); Thanks&Regards Vinay
|
 |
Christophe Verré
Sheriff
Joined: Nov 24, 2005
Posts: 14672
|
|
|
You've got to use a formatter as in your first output, to get the desired format. Calling print on a Date instance will call Date.toString(), which uses "dow mon dd hh:mm:ss zzz yyyy" as the output format.
|
[My Blog]
All roads lead to JavaRanch
|
 |
 |
|
|
subject: Example of convert String to Date
|
|
|