我試圖將一些日期時間值作爲字符串從某些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