Best way to convert JavaScript date to .NET date

前端 未结 5 878
清歌不尽
清歌不尽 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:26

    Expanding on @Naraen's answer, my javascript date was in the following format:

    Thu Jun 01 2017 04:00:00 GMT-0400 (Eastern Standard Time)
    

    Which required two lower case d's for the day (dd) for the conversion to work for me in C#. See update to @Naraen's code:

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

提交回复
热议问题