Created
March 4, 2020 12:03
-
-
Save silviogarbes/a3ddd20207440c7b421a734268c67d69 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// Convert Excel dates into JS date objects | |
// | |
// @param excelDate {Number} | |
// @return {Date} | |
function dateFromExcel(excelDate){ | |
/* In excel 02/29/1900 it exists, in javascript this day does not exist and changes to 03/01/1900. Leap year problem. So the minus 1 */ | |
var dt = new Date(1900,0,0); | |
dt.setDate(dt.getDate() - 1 + excelDate); | |
return dt | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// Example:
// var test = dateFromExcel(43893)
// test
// return: Tue Mar 03 2020 00:00:00 GMT-0300 (Horário Padrão de Brasília)
// test.getTime()
// return: 1583204400000
// test.toLocaleDateString()
// return: "03/03/2020"
// test.toLocaleString()
// return: "03/03/2020 00:00:00"
// test.toLocaleTimeString()
// return: "00:00:00"
// test.toISOString()
// return: "2020-03-03T03:00:00.000Z"
// test.toDateString()
// return: "Tue Mar 03 2020"
// test.toUTCString()
// return: "Tue, 03 Mar 2020 03:00:00 GMT"
// test.toString()
// return: "Tue Mar 03 2020 00:00:00 GMT-0300 (Horário Padrão de Brasília)"
// test.valueOf()
// return: 1583204400000