Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

string to date parsing ....

 
sekhar sp
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I execueted the following code, but i get the output of the date in different format ....can someone tell me wats wrong in this code.

I want the output of the date to be in "dd/MM/yyyy" format.


CODE:
String strDate = "14/08/2008";
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
Date tempDate = df.parse(strDate);

System.out.println(" DATE format ="+tempDate);


OUTPUT:
DATE format =Thu Aug 14 00:00:00 IST 2008
 
Henry Wong
author
Marshal
Pie
Posts: 21122
78
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The parse() method takes a string, in a particular format and gets you a date object. This date object doesn't retain this format, it is merely a representation of the date.

If you want to print in a particular format, either (1) use the original string, or (2) generate a new string with the format() method.

Henry
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic