In PHP, you can easily convert an English textual datetime description into a proper date with strtotime()
.
Is there anything similar in Javascript?
Return Values PHP strtotime() function returns a timestamp value for the given date string. Incase of failure, this function returns the boolean value false.
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
There is not. The closest built-in option is Date.parse()
, which parses a very limited subset of what strtotime()
can:
var ts = Date.parse("2010-10-29");
It's worth noting that this function returns milliseconds instead of seconds, so you need to divide the result by 1000 to get an equivalent value to PHP's function.
I found this article and tried the tutorial. Basically, you can use the date constructor to parse a date, then write get the seconds from the getTime()
method
var d=new Date("October 13, 1975 11:13:00"); document.write(d.getTime() + " milliseconds since 1970/01/01");
Does this work?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With