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 Java in General and the fly likes  how to parse string to date with defualt format?    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 » Java in General
Reply Bookmark " how to parse string to date with defualt format?    " Watch " how to parse string to date with defualt format?    " New topic
Author

how to parse string to date with defualt format?

Simpson Kumar
Ranch Hand

Joined: Mar 19, 2008
Posts: 260
is there any possibilities to parse a string to date if we don't specify the format in SDF?

In database we have different formats and we need to convert each one convert to date with common format(something like default), is there any possibilities to do in java?


Thanks,
Kumar
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12929
    
    3

Parsing a date string without knowing the format is impossible in general. Suppose you get the string "07/08/2009" - how can you see if this means 7 August 2009 (DD/MM/YYYY) or 8 July 2009 (MM/DD/YYYY)?

You could do it by trying to parse a string with a different number of formats, but this will not solve the problem of ambiguous dates.

There is no method in the standard Java API to parse a string into a Date object without knowing the format.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
pete stein
Bartender

Joined: Feb 23, 2007
Posts: 1561
Also, please read the FAQ about being forthright when cross-posting the same question in multiple fora. This question has been fully answered in the forums.sun.com fora.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: how to parse string to date with defualt format?
 
Similar Threads
how to change a date in desired format
String date and Object date comparisons
how to convert String into Date format
How to convert this String into a readable date?
Date validation