在Excel.js中将Excel Date字符串转换为Unix时间

时间:2021-02-19 22:01:55

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

我使用node-xlsx解析Node.js中的Excel文件,但是在解析之前,Date单元格有奇怪的视图:

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?

我如何将此字符串42430.32226851852转换为Unix时间格式?

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

其中1157410是~1秒

1 个解决方案

#1


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.

另一个解决方法是,当您将其保存到Excel文档时,将其保存为字符串而不是Date对象。

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

然后你可以把它作为一个字符串读取,然后将它包装在一个新的Date()中

#1


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.

另一个解决方法是,当您将其保存到Excel文档时,将其保存为字符串而不是Date对象。

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

然后你可以把它作为一个字符串读取,然后将它包装在一个新的Date()中