i suggest you use moment.js for this. In moment.js you can:
var localTime = moment().format('YYYY-MM-DD'); // store localTime
var proposedDate = localTime + "T00:00:00.000Z";
now that you have the right format for a time, parse it if it's valid:
var isValidDate = moment(proposedDate).isValid();
// returns true if valid and false if it is not.
and to get time parts you can do something like:
var momentDate = moment(proposedDate)
var hour = momentDate.hours();
var minutes = momentDate.minutes();
var seconds = momentDate.seconds();
// or you can use `.format`:
console.log(momentDate.format("YYYY-MM-DD hh:mm:ss A Z"));
i suggest you use
moment.js
for this. In moment.js you can:now that you have the right format for a time, parse it if it's valid:
and to get time parts you can do something like:
More info about momentjs http://momentjs.com/
It's a part of ISO-8601 date representation. It's incomplete because a complete date representation in this pattern should also contains the date:
If you try to parse this date as it is you will receive an
Invalid Date
error:So, I guess the way to parse a timestamp in this format is to concat with any date
Then you can extract only the part you want (timestamp part)