• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Devaka Cooray
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Saloon Keepers:
  • Tim Holloway
Bartenders:

how to parse string to date with defualt format?

 
Ranch Hand
Posts: 261
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 1561
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Then YOU must do the pig's work! Read this tiny ad. READ IT!
The new gardening playing cards kickstarter is now live!
https://www.kickstarter.com/projects/paulwheaton/garden-cards
reply
    Bookmark Topic Watch Topic
  • New Topic