wood burning stoves 2.0
The moose likes Java in General and the fly likes Example of  convert  String to Date Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Example of  convert  String to Date" Watch "Example of  convert  String to Date" New topic

Example of convert String to Date

Kumar Naidu

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);
Date ss =formatter1.parse(myDate);

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");

Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

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
I agree. Here's the link: http://aspose.com/file-tools
subject: Example of convert String to Date
It's not a secret anymore!