This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund 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
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply 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: 16695
    
  19


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: 14672
    
  11

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: 14672
    
  11

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
Convert to timestamp yyyy-MM-dd hh:mm:ss a
Handling a strange date format
Reformating date
problem while insert date data in mysql
Different output converting dates to msecs!