This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Java date conversion confusion... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java date conversion confusion..." Watch "Java date conversion confusion..." New topic
Author

Java date conversion confusion...

bob reilly
Ranch Hand

Joined: Jan 22, 2007
Posts: 44
I'm having an issue converting dates in Java. Here's my syntax:



Very frustrating. Any constructive comments / criticism is appreciated. Thanking you in advance...

Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18139
    
  39


Date objects doesn't have a configurable format. If you just print it, you will get a preset format, as you have seen.

If you want a particular format, you will need to format() it to a string and print it -- as you have done earler in the example.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
vinay babu reddy
Greenhorn

Joined: May 25, 2010
Posts: 6
Hi,

There is no way to convert string object to date object in java, but the vice versa will possible.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

bob, UseCodeTags the next time you post some code. I have added them this time.


[My Blog]
All roads lead to JavaRanch
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

vinay babu reddy wrote:Hi,

There is no way to convert string object to date object in java, but the vice versa will possible.

You might have misunderstood the question. And yes, you can convert strings into dates. That's what dateFormat.parse is doing in the code above.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java date conversion confusion...
 
Similar Threads
Reformating date
Handling a strange date format
problem while insert date data in mysql
Convert to timestamp yyyy-MM-dd hh:mm:ss a
Different output converting dates to msecs!