The moose likes Java in General and the fly likes Converting string to specific date format Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Converting string to specific date format" Watch "Converting string to specific date format" New topic
Author

Converting string to specific date format

Thanuja Vishwanath
Ranch Hand

Joined: Oct 07, 2010
Posts: 49

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.




Thanks,
Thanuja.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18993
    
    8

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Converting string to specific date format