admin管理员组文章数量:1291135
I know that Highcharts can take Unix Offset time natively, but it's more readable to pass it a Date object:
Date.UTC(2003,8,25)
Is there any way for Moment.js to output this exact object?
var momentDate = moment.utc([2003, 08, 25]);
var JSDate = momentDate.toDate();
//Not sure where to go to actually output Date.UTC(2003,8,25)
I know that Highcharts can take Unix Offset time natively, but it's more readable to pass it a Date object:
Date.UTC(2003,8,25)
Is there any way for Moment.js to output this exact object?
var momentDate = moment.utc([2003, 08, 25]);
var JSDate = momentDate.toDate();
//Not sure where to go to actually output Date.UTC(2003,8,25)
Share
Improve this question
asked Dec 6, 2014 at 11:33
fuzzybabybunnyfuzzybabybunny
5,2546 gold badges36 silver badges61 bronze badges
1 Answer
Reset to default 12I think there may be some confusion as to the functionality of Date.UTC
.
Date.UTC()
does not return a Date object. It returns the number of milliseconds between a specified date and midnight of January 1, 1970, according to universal time. This is exactly what Highcharts wants. As you suggest, it is way more human-readable than typing the number of milliseconds itself. For example:
var d = Date.UTC(2012,02,30);
// d holds the value 1333065600000
Similar functionality in Moment.js can be achieved with the valueOf()
method:
var d = moment.utc([2012,02,30]).valueOf();
// d holds the value 1333065600000
本文标签: javascriptUsing Moment to output DateUTC() object for HighChartsStack Overflow
版权声明:本文标题:javascript - Using Moment to output Date.UTC() object for HighCharts? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741526288a2383486.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论