问题
I am using Appcelerator Titanium, and I'm trying to parse a date string as a new Date object and then use the .getTime()
function but it keeps returning "NaN"
var d = new Date("2014-02-01T00:00:00");
var time = d.getTime();
console.log(time); // returns NaN
Am I doing anything wrong here? It works when I create a new date for now, like this:
var d = new Date();
var time = d.getTime();
console.log(time); // returns correct value
I can't see why the first example is working but the second example is not.
回答1:
You're trying to parse a UTC date time. In Titanium, when you try to parse the date, it will return invalid date. So you need to convert it to datetime string. You can use Convert UTC Date to datetime string Titanium to convert the time.
来源:https://stackoverflow.com/questions/21580904/appcelerator-titanium-js-dosent-parse-date-as-expected