How to Convert a Date String to UTC date using Javascript?
This question already has an answer here:
try toISOString()
on the Date object. If using less than ECMAScript 5, there is a polyfill for the function
if ( !Date.prototype.toISOString ) {
( function() {
function pad(number) {
if ( number < 10 ) {
return '0' + number;
}
return number;
}
Date.prototype.toISOString = function() {
return this.getUTCFullYear() +
'-' + pad( this.getUTCMonth() + 1 ) +
'-' + pad( this.getUTCDate() ) +
'T' + pad( this.getUTCHours() ) +
':' + pad( this.getUTCMinutes() ) +
':' + pad( this.getUTCSeconds() ) +
'.' + (this.getUTCMilliseconds() / 1000).toFixed(3).slice( 2, 5 ) +
'Z';
};
}() );
}
There is an UTC method of Date. It should be as simple as:
new Date(Date.UTC(a[2],parseInt(a[1], 10) - 1,a[0]));
链接地址: http://www.djcxy.com/p/46590.html