I have a select menu with options looking something like this...

<option value="2013, 2, 1">01/03/2013</option>

I want to create an array of the dates from this menu but as milliseconds

so I need something like:

myArray = [1368140400000,... etc]

Any ideas how I can get this? I've tried this so far but it doesn't work, returning NaN instead.

var startDates = new Array;
$("select.startdates").find("option").each( function() {
    startDates.push(new Date($(this).val()).getTime()) 
});
有帮助吗?

解决方案

2013, 2, 1 is no valid date that is recognized by Date.parse. This should work better:

var ms = Date.UTC.apply(Date, this.value.split(",").map(Number));

However, I think it should be easier to store the milliseconds themselves in the option value, so that you can easily use new Date(parseInt(this.value, 10))

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top