JSON itself doesn't care what format you use for the date. However, it is most commonly used in the JavaScript format which is ISO 8601 format.
That being said, you can create a string in this format using the following VB6 code (The below returns the time in UTC, if you want to use the local time you will need to call GetLocalTime
API instead of 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