I'm trying to let users type in date and time values into an input field. Some examples may include:
Tomorrow at 3pm
Now
Today at 1pm
Next tuesday 4pm
How would I go about parsing such readable text into date/time strings?
E.g. dd/mm/yyyy hh:mm
Can it be done client-side using jquery or must it be done ajax through php?
Thanks in advance for any advice or insights :)
The Date. parse() method parses a string representation of a date, and returns the number of milliseconds since January 1, 1970, 00:00:00 UTC or NaN if the string is unrecognized or, in some cases, contains illegal date values (e.g. 2015-02-31). Only the ISO 8601 format ( YYYY-MM-DDTHH:mm:ss.
Using strptime() , date and time in string format can be converted to datetime type. The first parameter is the string and the second is the date time format specifier. One advantage of converting to date format is one can select the month or date or time individually.
There is an open source javascript library doing all that funky stuff with dates. You can check out http://www.datejs.com/
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