时间日期对象 JavaScript getUTCMilliseconds
Time Date Objects JavaScript getUTCMilliseconds
从 Chrome 控制台:
Me: var dateObj = new Date("2013-04-14 11:48");
undefined
Me: dateObj
Sun Apr 14 2013 11:48:00 GMT+0200 (Central Europe Daylight Time)
Me: dateObj.getUTCMilliseconds();
0
谁能告诉我为什么这些日期函数不起作用?我想获取一个日期字符串并将其转换为 UTC 毫秒。如您所见,我将字符串传递给 Date 构造函数,然后将函数 getUTCMilliseconds() 应用于返回的日期对象。为什么它返回零??
你可以使用 JavaScript Date valueOf() Method.
Return the primitive value of a Date object:
dateObj.valueOf()
1365929280000
结果是正确的——对函数名的理解是错误的(我也是)。
Date.getUTCMilliseconds()
被定义为 return 日期的毫秒部分 与 getMinutes()
returns 相同存储在对象中的分钟数(在您的示例中,即 return 48 分钟)。
澄清一下,关于你的约会 [2013-04-14 11:48]
各个部分是:
getFullYear()
=== 2013
getDate()
=== 14
getSeconds()
=== 0(因为你的日期字符串定义了整数分钟)
getMilliseconds()
=== 0(同理)
一个反例可能是[2017-11-15 16:53:10.78]
:
getSeconds()
=== 10
getMilliseconds()
=== 78
The functions on Date
are laid out nicely on the W3Schools page here.
我看起来你是在追求 Unix 时间戳值 e(这是 Google 带我来这里时我想要的)。
Date.getTime()
将 return 自 1970/01/01 以来的毫秒数
幸运的是,这是当前实现中的基础值,。
从 Chrome 控制台:
Me: var dateObj = new Date("2013-04-14 11:48");
undefined
Me: dateObj
Sun Apr 14 2013 11:48:00 GMT+0200 (Central Europe Daylight Time)
Me: dateObj.getUTCMilliseconds();
0
谁能告诉我为什么这些日期函数不起作用?我想获取一个日期字符串并将其转换为 UTC 毫秒。如您所见,我将字符串传递给 Date 构造函数,然后将函数 getUTCMilliseconds() 应用于返回的日期对象。为什么它返回零??
你可以使用 JavaScript Date valueOf() Method.
Return the primitive value of a Date object:
dateObj.valueOf()
1365929280000
结果是正确的——对函数名的理解是错误的(我也是)。
Date.getUTCMilliseconds()
被定义为 return 日期的毫秒部分 与 getMinutes()
returns 相同存储在对象中的分钟数(在您的示例中,即 return 48 分钟)。
澄清一下,关于你的约会 [2013-04-14 11:48]
各个部分是:
getFullYear()
=== 2013getDate()
=== 14getSeconds()
=== 0(因为你的日期字符串定义了整数分钟)getMilliseconds()
=== 0(同理)
一个反例可能是[2017-11-15 16:53:10.78]
:
getSeconds()
=== 10getMilliseconds()
=== 78
The functions on Date
are laid out nicely on the W3Schools page here.
我看起来你是在追求 Unix 时间戳值 e(这是 Google 带我来这里时我想要的)。
Date.getTime()
将 return 自 1970/01/01 以来的毫秒数
幸运的是,这是当前实现中的基础值,