diff --git a/strftime.js b/strftime.js index 6845863..1d06d10 100644 --- a/strftime.js +++ b/strftime.js @@ -280,14 +280,22 @@ } function dateToUTC(d) { - return new Date( - d.getUTCFullYear(), + var year = d.getUTCFullYear(); + var date = new Date( + year, d.getUTCMonth(), d.getUTCDate(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), - d.getUTCMilliseconds()); + d.getUTCMilliseconds() + ); + // In old dates, years is incorrectly interpreted as a 2-digit year with base 1900. + // Correct this by setting the year explicitly after the fuzzy creation process. + if (date.getFullYear() != year) { + date.setFullYear(year); + } + return date; } var RequiredDateMethods = ['getTime', 'getTimezoneOffset', 'getDay', 'getDate', 'getMonth', 'getFullYear', 'getYear', 'getHours', 'getMinutes', 'getSeconds'];