如何在excel中将数字转换为日期时间格式(我在R中实现了等效的解决方案)

Jer*_*emy 1 excel r date-format excel-formula excel-dates

在此处输入图片说明

参考上面的屏幕截图,我正在尝试从新加坡证券交易所抓取数据,该数据是从返回 json 的 API 调用动态加载的 Web 内容,示例在这里

我对日期有一些问题,这是由 json 给出的数字。例如,1575491760000应该是2019-12-04 20:36:00GMT

经过一些反复试验,我想出了使用 R 的解决方案:

as.POSIXct(1575491760000/1000, origin="1970-01-01", tz = 'GMT')  
# not sure why need to divide the number by 1000 here but i guess this is the way to make it work
Run Code Online (Sandbox Code Playgroud)

上面的代码确实"2019-12-04 20:36:00 GMT"在 R中返回。

但是,我的问题是在 Excel 中是否有上述转换的解决方案?我尝试了几种不同的方法,但没有一种方法可以处理这么长的数据场景(日期 + 时间格式)。如果有人可以提供具体的解决方案,不胜感激!

Jon*_*ing 8

这是 Excel 等效项。

=DATE(1970,1,1) + 1575491760000/(1000*60*60*24)
# 12/4/19 20:36:00  with cell formatting set to   m/d/yy h:mm:ss
Run Code Online (Sandbox Code Playgroud)

自 1970 年 1 月 1 日起,Unix 时间每毫秒增加 1。自 1900 年 1 月 1 日起,Excel 日期时间每天递增一。

因此,要将 UNIX 时间转换为 excel,请除以一天中的毫秒数 ( 1000*60*60*24) 并添加到日期 1/1/70(25569在 Excel 中。)