Trying to convert a string to Javascript Date. My string:
var fullDate = this.date + " " + this.time + ":00";
gives an output: 24/12/2016 02:00:00
but trying to convert it in js Date object like:
var k = new Date(fullDate);
gives the output: Invalid Date
or even: var k = Date.parse(fullDate);
gives the output: NaN
Any help is welcome.
I was following instructions from http://www.datejs.com/ so far
The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long ( YYYY-MM-DDTHH:mm:ss.sssZ or ±YYYYYY-MM-DDTHH:mm:ss.sssZ , respectively). The timezone is always zero UTC offset, as denoted by the suffix Z .
To format a date as dd/mm/yyyy:Use the getDate() , getMonth() and getFullYear() methods to get the day, month and year of the date. Add a leading zero to the day and month digits if the value is less than 10 .
The static Date.now() method returns the number of milliseconds elapsed since January 1, 1970 00:00:00 UTC.
Your format is invalid. Valid format is month/day/year
, so try:
var fullDate = "12/24/2016 02:00:00";
var k = new Date(fullDate);
Hope I could help!
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