File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "string to date parsing ...." Watch "string to date parsing ...." New topic

string to date parsing ....

sekhar sp

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.

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

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

DATE format =Thu Aug 14 00:00:00 IST 2008
Henry Wong

Joined: Sep 28, 2004
Posts: 20535

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.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
I agree. Here's the link:
subject: string to date parsing ....
It's not a secret anymore!