Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

Regarding date conversion

 
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am facing problem with parsing date,means I am getting a date as a string and then parsing it with some specific format like dd:MM:YYYY HH:mm:ss,but this gives exception when the format doesn't match with the one which I am expecting some thing like If I expect dd:MMM:yy HH:mm:ss but if it comes differently then my code is breaking with ParseException.The incoming date format I cant guess as they are already formatted in the database using to_date.Please tell me solution.

Thanks in advance...
 
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
What exactly does the string you are trying to parse look like, and which date pattern are you using exactly? If they don't match, you get a ParseException.

Note that the date pattern is case-sensitive. Upper-case YYYY means something different than lower-case yyyy. Make sure you use the correct letters in the pattern. The API documentation of java.text.SimpleDateFormat explains exactly what the pattern should look like.

Ofcourse you need to know exactly what the format is of dates you are trying to parse. Java won't guess automatically for you.
[ September 28, 2007: Message edited by: Jesper Young ]
 
Naveen Koneti
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jesper,

Our application is a very big application and it is a old one.So what the existing implementation doing is they are formatting the dates in these probable formats

1)dd-MM-yyyy HH:mm:ss
2)yyyy-MM-dd HH:mm:ss
3)dd-MMM-yy HH:mm:ss

And which format occurs when and in which page I dont know that.

what my requirement is when I encounter any date (it may come as java.util.Date or String)in the jsp I have to convert it according to the user Time zone and display.As of now it is not feasible to find the exact format of the date which is coming as there are 2000+ jsps present in my application.Is there any way to know the format of the date at runtime,I mean a generalized logic to determine the format of the source date ? so that I can take it parse and show to the user in the same format.

Please advice....

Thanks in advance
 
Sheriff
Posts: 22684
128
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well you can try parsing the strings using one format at a time, and then fail if all formats fail. It's exactly what )]DateUtils.parseDate from the Jakarta Commons Lang Library does.

If you don't want to use that library you can do the same yourself:
 
Naveen Koneti
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks rob .....
 
Montana has cold dark nights. Perfect for the heat from incandescent light. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic