Appcelerator Titanium JS dosen't parse Date() as expected

纵然是瞬间 提交于 2019-12-24 04:21:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!