• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Converting string to specific date format

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi,

I have this requirement where i will get the date and time as string. Everytime this date and time string will vary in format ie.dd-MMM-yy format or dd/MMM/yy or MMM/dd/yy etc.

Now my problem is i want to parst this string to particular date format which iam not able to do as the original date string format differs for each case.

Iam able to convert the given string to date in specific format as below if i know the original date string format . But how do i do this if iam not aware of the original string format.



 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Thanuja Vishwanath wrote:I am able to convert the given string to date in specific format as below if i know the original date string format . But how do i do this if i am not aware of the original string format.



It depends on what the possible list of unknown formats will be. For example if you were given "02-12-11" without being told the format, would that be February 12, 2011? Or would it be 02 December, 2011? Or perhaps 2002 December 11?

However if you have a list of possible formats which don't have any ambiguities like the example above, then just try them all until you find one which doesn't throw an exception.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic