我在文本框中的VB6(而不是.NET)中获得了这个JSON:
[{"id":123,"key":"h73df", "birth_date":"20180101"}]
发布到网址时没有返回任何错误..但是没有插入日期,我也不知道为什么。
我已经尝试过不同的格式:
"2018.01.01"
["20180101"]
2018.01.01
但是没有工作。我想我必须使用cdate()
这样的东西,但是我把所有的JSON字符串放到一个文本框中,所有这些都变成了一个简单的字符串......并且不起作用。
答案 0 :(得分:0)
JSON本身并不关心您使用的日期格式。但是,它最常用于ISO 8601格式的JavaScript格式。
话虽这么说,您可以使用以下VB6代码创建此格式的字符串(以下以UTC格式返回时间,如果您想使用本地时间,则需要调用GetLocalTime
API而不是GetSystemTime
):
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Put inside module:
Private Type SYSTEMTIME '16 Bytes
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type
Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Function GetJsonDateTime() As String
Dim NowTime As SYSTEMTIME
Dim sYear, sMonth, sDayOfWeek, sDay, sHour, sMinute, sSecond, sMilliseconds As String
Dim JsonDateTime As String
GetSystemTime NowTime
sYear = Format(NowTime.wYear, "0000")
sMonth = Format(NowTime.wMonth, "00")
sDay = Format(NowTime.wDay, "00")
sHour = Format(NowTime.wHour, "00") 'wHour - or + X depends local timezone
sMinute = Format(NowTime.wMinute, "00")
sSecond = Format(NowTime.wSecond, "00")
sMilliseconds = Format(NowTime.wMilliseconds, "000")
JsonDateTime = sYear & "-" & sMonth & "-" & sDay & "T" & sHour & ":" & sMinute & ":" & sSecond & "." & sMilliseconds & "Z"
GetJsonDateTime = JsonDateTime
End Function