如何将json响应日期字符串转换为c#日期格式?

时间:2018-09-10 04:55:08

标签: c# json

我有json字符串,例如“ 1536476400000”,并使用C#转换为“ yyyy-MM-dd”格式。请帮助我

2 个答案:

答案 0 :(得分:5)

解决的答案是...

String offset = "1536476400000";
double spotQuoteEffDate = double.Parse(offset );
TimeSpan spotQuoteEffDateTime = TimeSpan.FromMilliseconds(spotQuoteEffDate);
DateTime spotQuote = new DateTime(1970, 1, 1) + spotQuoteEffDateTime;

输出是...

spotQuote = 9/9/2018 7:00:00 AM

答案 1 :(得分:2)

请参考以下代码,

  TimeSpan s = TimeSpan.FromMilliseconds(double.Parse("1536476400000" ));
  DateTime dt = new DateTime(1970, 1, 1) + s;
  Console.writeline(String.Format("{0:yyyy-MM-dd}",dt));