Is there any function or library which gets a date in milliseconds, given a String
?
This question shows how to convert a formatted String
to a Date
object, but is there any way to do this with an unformatted String
?
Is there any function or library which gets a date in milliseconds, given a String
?
This question shows how to convert a formatted String
to a Date
object, but is there any way to do this with an unformatted String
?
Basically, the task is impossible. Here's an example:
01/04/2012
In the US, that means January 4th 2012. In Australia, that mean 1st April 2012.
Without knowing where you are and what date formats conventionally mean, it is impossible to accurately map an arbitrary date-like string to a date time value that matches what the user actually meant.
And even if you do know about the relevant local conventions, users have a remarkable propensity to be oblivious to ambiguity. Dealing with that may require deep domain knowledge (or mind reading skills!) to disambiguate the possible meanings.
When you think about it, this is why modern user interfaces typically use a date-picker widget of some kind when the user needs to enter a date / time
first convert the string to Date
. From there you can get time in milis using Date.getTime() method