将JSON日期转换为MM / DD / YYYY格式?

时间:2022-06-30 09:32:00

My client receives a spreadsheet with a number of columns, one being a "date". Only the date turns out to be formatted as Date(1292291582263-0700) (a JSON date it seems).

我的客户收到一个包含多个列的电子表格,其中一列是“日期”。只有日期结果被格式化为日期(1292291582263-0700)(似乎是一个JSON日期)。

I need to convert and work with this JSON date in MM/DD/YYYY format, elsewhere in this spreadsheet's code (VBA).

我需要转换并使用此电子表格代码(VBA)中其他地方的MM / DD / YYYY格式的JSON日期。

Does anyone know how to parse and convert this JSON date format into a MM/DD/YYYY format? I have read lots of solutions on SO that are in Javascript, C#, or ASP.NET, etc but all I have to work with is Excel 2010 and VBA code for this project. Is there way to arrive at a readable format as I need?

有谁知道如何解析并将此JSON日期格式转换为MM / DD / YYYY格式?我已经阅读了大量有关Javascript,C#或ASP.NET等的解决方案,但我必须使用的是Excel 2010和此项目的VBA代码。有没有办法达到我需要的可读格式?

1 个解决方案

#1


6  

Millisecond Epoch time with a +/- offset?

具有+/-偏移的毫秒纪元时间?

Const test = "1292291582263-0700"

Dim dt As String: dt = Left$(test, 13)
Dim off As String: off = Mid$(test, 14)

Dim d As Date: d = DateAdd("s", CCur(dt) / 1000, "01/01/1970")
Debug.Print d
<<< 14/12/2010 01:53:02 

d = DateAdd("h", Left$(off, 3), d)
d = DateAdd("n", Right$(off, 2), d)
Debug.Print d
<<< 13/12/2010 18:53:02 

#1


6  

Millisecond Epoch time with a +/- offset?

具有+/-偏移的毫秒纪元时间?

Const test = "1292291582263-0700"

Dim dt As String: dt = Left$(test, 13)
Dim off As String: off = Mid$(test, 14)

Dim d As Date: d = DateAdd("s", CCur(dt) / 1000, "01/01/1970")
Debug.Print d
<<< 14/12/2010 01:53:02 

d = DateAdd("h", Left$(off, 3), d)
d = DateAdd("n", Right$(off, 2), d)
Debug.Print d
<<< 13/12/2010 18:53:02