我试图将一些日期时间值作为字符串从某些Javascript代码传递到VB.net日期时间对象。Javascript日期转换为VB.net日期时间
这是林试图转换
星期四2012年9月27日14点21分42秒GMT + 0100(BST)
这里是我到目前为止,但它是真的努力转换此日期字符串
Public Function TryParseDate(dDate As String) As Date
Dim enUK As New CultureInfo("en-GB")
Dim Converted_Date As Nullable(Of Date) = Nothing
Dim Temp_Date As Date
Dim formats() As String = {"ddd MMM d yyyy HH:mm:ss GMTzzz (BST)", _
"ddd MMM d yyyy HH:mm:ss GMTzzz", _
"ddd MMM d yyyy HH:mm:ss UTCzzz"}
' Ensure no leading or trailing spaces exist
dDate = dDate.Trim(" ")
' Attempt standard conversion and if successful, return the date
If Date.TryParse(dDate, Temp_Date) Then
Converted_Date = Temp_Date
Else
Converted_Date = Nothing
End If
' Standard date parsing function has failed, try some other formats
If IsNothing(Converted_Date) Then
If Date.TryParseExact(dDate, formats, enUK, DateTimeStyles.None, Temp_Date) Then
Converted_Date = Temp_Date
Else
Converted_Date = Nothing
End If
End If
' Conversion has failed
Return Converted_Date
End Function
TryParse和TryParseExact函数都返回false,指示转换失败。有谁知道发生了什么事?或者更好的是,有一些代码将成功转换日期时间字符串。 有谁知道为什么这不起作用,并且
如果你有Javascript代码的控制,你可以使用'foo.toISOString( )'制作一个符合ISO 8601的字符串,这很容易制作成DateTime对象。 – 2013-03-11 11:31:03