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
Add a ment  | 

1 Answer 1

Reset to default 12

I 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