I have to parse a date and time string of format "2015-01-16 22:15:00". I want to parse this into JavaScript Date Object. Any help on this?
I tried some jquery plugins, moment.js, date.js, xdate.js. Still no luck.
I have to parse a date and time string of format "2015-01-16 22:15:00". I want to parse this into JavaScript Date Object. Any help on this?
I tried some jquery plugins, moment.js, date.js, xdate.js. Still no luck.
I was trying to use moment.js guys. But since I was having this error, "ReferenceError: moment is not defined", I had to skip it for now. I am using an temporary workaround for now.
With moment.js you can create a moment object using the String+Format constructor:
Then, you can convert it to JavaScript Date Object using toDate() method:
If you are sure it's in the desired format and don't need to error check, you can parse it manually using split (and optionally replace). I needed to do something similar in my project (MM/DD/YYYY HH:mm:ss:sss) and modified my solution to fit your format. Notice the subtraction of 1 in the month.
A better solution, I am now using date.js - https://code.google.com/p/datejs/
I included the script in my html page as this -
Then I simply parsed the date string "2015-01-16 22:15:00" with specifying the format as,
See Date.parse().
The string must be in the ISO-8601 format. If you want to parse other formats use moment.js.