Reputation: 77
I am trying to read excel data using sheetjs xlsx npm library. I am getting wrong date when i tried with chrome browser. If i use Firefox, the date value is correct. Can anyone help me to resolve this issue.
Eg: I am trying to read date from excel is : 2021-08-01
Result i am getting is : 2021-07-31
Code:
------
const wb = XLSX.read(bufferArray, { type: "buffer", dateNF: "YYYY-MM-DD", cellDates: true, cellNF: false, cellText: true });
const wsname = wb.SheetNames[0];
const ws = wb.Sheets[wsname];
const data = XLSX.utils.sheet_to_json(ws);
Upvotes: 1
Views: 2085
Reputation: 151
This is something to do with the specification of dates in Chrome and Firefox
When parsing a date as a string without an explicit time, Chrome will default the Date object's time to midnight local time. Firefox will default it to midnight GMT.
Do have a look at the following issues for further details Sheet js response.
difference in dates github issue
So basically the Dates will be converted based on the application used:
As per my understanding, the result from both chrome and Node.Js will be the same.
One other thing to keep in mind is that
Chrome gives you the time in UTC+0, while Firefox gives you the time in GMT+0530
It is always a good practice to convert the dates to a common format and then pass it to the sheetJS module.
Upvotes: 1