Sub UTCToLocal(UTCTimeString As String) As Long
' Sun Jan 05 22:54:05 +0000 2014
Dim RegExPat1 As String = "((?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday|Tues|Thur|Thurs|Sun|Mon|Tue|Wed|Thu|Fri|Sat))" & "(\s+)" & _
"((?:Jan(?:uary)?|Feb(?:ruary)?|Mar(?:ch)?|Apr(?:il)?|May|Jun(?:e)?|Jul(?:y)?|Aug(?:ust)?|Sep(?:tember)?|Sept|Oct(?:ober)?|Nov(?:ember)?|Dec(?:ember)?))" & "(\s+)" & _
"(\d+)(\s+)(\d+)(.)(\d+)(.)(\d+)(\s+)([-+]\d+)(\s+)((?:(?:[1]{1}\d{1}\d{1}\d{1})|(?:[2]{1}\d{3})))(?![\d])"
' 2014-01-01T03:08:04+0000
Dim RegExPat2 As String = "((?:2|1)\d{3}(?:-|\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1]))(?:T|\s)(?:(?:[0-1][0-9])|(?:2[0-3])):(?:[0-5][0-9]):(?:[0-5][0-9]))" & _ 'Time Stamp 1'
"([-+]\d+)"
' 2014-01-02T17:06:18.866Z
Dim RegExPat3 As String = "((?:2|1)\d{3}(?:-|\/)(?:(?:0[1-9])|(?:1[0-2]))(?:-|\/)(?:(?:0[1-9])|(?:[1-2][0-9])|(?:3[0-1]))(?:T|\s)(?:(?:[0-1][0-9])|(?:2[0-3])):(?:[0-5][0-9]):(?:[0-5][0-9]))" & _
"(\.)(\d)(\d)(\d)(Z)"
Dim psDateFmt As String
Dim plTicks As Long = 0
If Regex.IsMatch2(RegExPat1, Regex.CASE_INSENSITIVE, UTCTimeString) = True Then
psDateFmt = "EEE MMM dd HH:mm:ss Z yyyy"
Else
If Regex.IsMatch2(RegExPat2, Regex.CASE_INSENSITIVE, UTCTimeString) = True Then
psDateFmt = "yyyy-MM-dd'T'HH:mm:ssZ"
Else
If Regex.IsMatch2(RegExPat3, Regex.CASE_INSENSITIVE, UTCTimeString) = True Then
psDateFmt = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
Else
Return -1
End If
End If
End If
Dim psCurrFmt As String
Dim piCurrOff As Int
psCurrFmt = DateTime.DateFormat
piCurrOff = DateTime.TimeZoneOffset
DateTime.DateFormat = psDateFmt
DateTime.SetTimeZone(0)
plTicks = DateTime.DateParse(UTCTimeString)
DateTime.DateFormat = psCurrFmt
DateTime.SetTimeZone(piCurrOff)
Return plTicks
End Sub