DateTime.ParseExact format string

后端 未结 3 1739
清酒与你
清酒与你 2020-12-21 13:32

I have a web application that passes a DateTime from one page to another through the query string. It was working just fine in both IE and FireFox, but was throwing excepti

3条回答
  •  礼貌的吻别
    2020-12-21 14:11

    Might I suggest that instead of passing something like: "Wed Oct 03 2012 08:00:00 GMT-0400 (Eastern Daylight Time)" in your query string, that instead you simply pass the timestamp of the date? E.g., new Date().getTime(). (Number of milliseconds since 1970 in UTC). Then, in C# you could just do:

    var epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
    var dt =  epoch.AddMilliseconds(Convert.ToInt64(Request.QueryString["start"]));
    

    No parsing required.

提交回复
热议问题