• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Converting string to specific date format

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • 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.



 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!