1

I use node-xlsx for parsing Excel file in Node.js but Date cells have strange view before parsing:

in Excel: 01.03.2016 07:44:04
in Node.js before parsing: 42430.32226851852

How I can convert this string 42430.32226851852 to Unix-time format?

Update: Write myself solution that work for me:

var xlsxDate = '42430.32226851852'
var splitDate=xlsxDate.split('.');
var unixTime=new Date(1900, 0, splitDate[0]-1, 0, 0, Math.round(splitDate[1]/1157410)).getTime()/1000
console.log(unixTime)

Where 1157410 is ~1 second

2
  • Hello Dan. I think this link can help you stackoverflow.com/questions/42183859/… Commented Oct 18, 2017 at 11:48
  • Thanks but not shure. I find information that dot point split 42430.32226851852 to date and time: 42430 - date (from 01.01.1900), 32226851852 - time. And now I dont understend how I can transform 32226851852 to normal time format. Excel is rounded 32226851852 to 32227 when i change cell format from Date to String Commented Oct 18, 2017 at 12:46

2 Answers 2

1

i use this code to convert Unix-time format:

date = new Date(( parseInt(excelDate) - (25567 + 2))*86400*1000)
unix = date.getTime()

Sign up to request clarification or add additional context in comments.

Comments

0

Another work around is that when you save it to your excel document you save it as a string and not a Date object.

Then you can read it as a string and just wrap it in a new Date()

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.