File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes string to date parsing .... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string to date parsing ...." Watch "string to date parsing ...." New topic
Author

string to date parsing ....

sekhar sp
Greenhorn

Joined: Aug 31, 2008
Posts: 2
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
Sheriff

Joined: Sep 28, 2004
Posts: 18748
    
  40

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


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: string to date parsing ....