How to parse date format?

后端 未结 2 970
盖世英雄少女心
盖世英雄少女心 2021-01-17 06:43

In one of the webservices my application is consuming, I encountered the following DateTime format.

\"/Date(1395780377459)/\"

Is this some stand

相关标签:
2条回答
  • 2021-01-17 06:56

    It looks like a unix timestamp:

    http://www.epochconverter.com/
    
    Tue, 25 Mar 2014 20:46:17 GMT
    

    In .NET:

    var epoch = new DateTime(1970,1,1,0,0,0,0,System.DateTimeKind.Utc);
    var dt = epoch.AddMilliseconds(1395780377459);
    

    (Source: How to convert a Unix timestamp to DateTime and vice versa?)

    0 讨论(0)
  • 2021-01-17 07:12

    I think the date is in milliseconds format. So you can try this:

    DateTime date = new DateTime(long.Parse(1395780377459));
    date.ToString("yyyy-MM-ddThh:mm:ssZ");
    

    or simply

    var time = TimeSpan.FromMilliseconds(1395780377459);
    

    Also the if the date is in json format then you may try this as mentioned in this answer:

    var date = new Date(parseInt(jsonDate.substr(6)));
    
    0 讨论(0)
提交回复
热议问题