用途自己理解XD
Date._parse = Date.parse;
Date.parse = function (date_str) {
//regex to match wc3dtf
var t = Date._parse(date_str);
if (isNaN(t)) {
var format = /(d{4})-(d{2})-(d{2})T(d{2}):(d{2}):((d{2}))?(?:([-+])(d{2}):?(d{2})|(Z))?/;
var match = date_str.match(format)
if (match) {
var year = match[1];
var month = match[2];
var day = match[3];
var hours = match[4];
var minutes = match[5];
var seconds = match[6];
//calc epoch for current date assuming GMT
var gmmktime = new Date();
gmmktime.setUTCFullYear(year);
gmmktime.setUTCMonth(month-1);
gmmktime.setUTCDate(day);
gmmktime.setUTCHours(hours);
gmmktime.setUTCMinutes(minutes);
gmmktime.setUTCSeconds(seconds);
var epoch = gmmktime.getTime();
var offset = 0;
if ( match[10] != 'Z' ) {
var tz_mod = match[8];
var tz_hour = match[9];
var tz_min = match[10];
// zero out the variables
if ( ! tz_hour ) { tz_hour = 0; }
if ( ! tz_min ) { tz_min = 0; }
var offset_secs = ((tz_hour*60)+tz_min)*60;
// is timezone ahead of GMT? then subtract offset
if ( tz_mod == '+' ) {
offset_secs = offset_secs * -1;
}
offset = offset_secs;
}
epoch = epoch + offset;
return epoch;
}
else {
return NaN;
}
} else {
return t;
}
}