从json字符串格式化dateTime

时间:2016-07-22 07:13:54

标签: datetime

我有一些JSON被返回...我如何使用c#和JS格式化这些日期时间字符串?

{
   "time": 1469257200,
   "summary": "Partly cloudy in the morning.",
   "icon": "partly-cloudy-day",
   "sunriseTime": 1469279237,
   "sunsetTime": 1469330841,
   "moonPhase": 0.63,
    ...... ..... ...
},

欢迎帮助!!!

1 个答案:

答案 0 :(得分:0)

一旦我意识到这是一个unix时间戳,

很容易:

        public static DateTime UnixTimeStampToDateTime(double unixTimeStamp)
          {
        // Unix timestamp is seconds past epoch
        System.DateTime dtDateTime = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
        dtDateTime = dtDateTime.AddSeconds(unixTimeStamp).ToLocalTime();
        return dtDateTime;
          }