Appcelerator Titanium JS 没有按预期解析 Date() [英] Appcelerator Titanium JS dosen't parse Date() as expected

查看:20
本文介绍了Appcelerator Titanium JS 没有按预期解析 Date()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 Appcelerator Titanium,我试图将日期字符串解析为新的 Date 对象,然后使用 .getTime() 函数,但它一直返回NaN"

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.

推荐答案

您正在尝试解析 UTC 日期时间.在 Titanium 中,当您尝试解析日期时,它将返回无效日期.所以你需要将它转换为日期时间字符串.您可以使用 Convert UTC Date to datetime string Titanium 来转换时间.

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.

这篇关于Appcelerator Titanium JS 没有按预期解析 Date()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆