Created
August 12, 2019 14:06
-
-
Save westc/4f250fc989d65c5f34a64990272a0e65 to your computer and use it in GitHub Desktop.
Function used to convert a numeric value (from Excel or Google Sheets) into a JavaScript Date object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts a numeric value (from Excel or Google Sheets) into a JavaScript Date object. | |
* @param {number} numDate - The numeric value that will be converted into a date. | |
* @param {?number=} opt_tzMinOffset - Optional. Defaults to the minute offset of the | |
* local timezone. If given this should indicate how many minutes to offset the date | |
* by to correctly represent the desired timezone. | |
* @returns {Date} - The date representation of the numeric value passed in. | |
*/ | |
function fromExcelDate(num, opt_tzMinOffset) { | |
return new Date( | |
(num - 25569) * 864e5 | |
+ (opt_tzMinOffset !== undefined ? -opt_tzMinOffset || 0 : (new Date).getTimezoneOffset()) * 6e4 | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment