Best way to convert JavaScript date to .NET date

前端 未结 5 876
清歌不尽
清歌不尽 2021-02-05 11:20

I have a date in JavaScript and its value is coming like this

Fri Apr 01 2011 05:00:00 GMT+0530 (India Standard Time) {}

Now what is the best way to convert th

5条回答
  •  孤城傲影
    2021-02-05 11:46

    Possible duplicate of the question answered here: Javascript date to C# via Ajax

    If you want local time, like you are showing in your question the following would do it.

    DateTime.ParseExact(dateString.Substring(0,24),
                                  "ffffd MMM d yyyy HH:mm:ss",
                                  CultureInfo.InvariantCulture);
    

    If you are looking for GMT time, doing a dateObject.toUTCString() in Javascript in the browser before you send it to the server, would do it.

提交回复
热议问题