Javascript日期转换为VB.net日期时间

Javascript日期转换为VB.net日期时间,javascript,vb.net,datetime,Javascript,Vb.net,Datetime,我正在尝试将作为字符串从一些Javascript代码传递的datetime值转换为VB.net datetime对象 这就是我想要改变的 2012年9月27日星期四14:21:42 GMT+0100(英国夏令时) 这是我到目前为止得到的,但它确实很难转换这个日期字符串 Public Function TryParseDate(dDate As String) As Date Dim enUK As New CultureInfo("en-GB") Dim Converted_D

我正在尝试将作为字符串从一些Javascript代码传递的datetime值转换为VB.net datetime对象

这就是我想要改变的

2012年9月27日星期四14:21:42 GMT+0100(英国夏令时)

这是我到目前为止得到的,但它确实很难转换这个日期字符串

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,表示转换失败。有人知道发生了什么事吗?或者更好的方法是,使用一些代码成功地转换日期时间字符串。
有人知道为什么这不起作用,并且您使用了错误的字符串格式吗。这里有一个f#中的例子,但你应该得到一个大概的想法:-)

希望能有帮助


mz

如果您可以控制Javascript代码,您可以使用
foo.toISOString()
生成符合ISO 8601的字符串,这很容易生成DateTime对象。很好,谢谢您……这很有效。我想知道单引号,但不是100%确定他们的确切用途。
open System
open System.Globalization

let main argv = 
    let date = "Thu Sep 27 2012 14:21:42 GMT+0100 (BST)"
    let dateparsed = DateTime.ParseExact(date, "ddd MMM dd yyyy HH:mm:ss 'GMT'zzzz '(BST)'", CultureInfo.InvariantCulture)
    printfn "%A" dateparsed
    0