解析在.NET返回JSON的日期? [英] Parsing a date returned as JSON in .net?
问题描述
您好我是从一个API作为JSON接收响应,并加载到我的应用程序。进口一切正常,只是针对某个特定项目的发布的日期。日期是返回一个数字我从来没有与之前:
Hi I was receiving responses from an API as JSON and loading it into my application. Everything imports fine except for a date that that a specific item was published on. The date is returned as a number which I never worked with before:
'date_created' : 1279643054
我试图用一个正常的DateTime.Parse(),没有运气。有谁知道如何分析这一点,或者如果有什么这是什么格式的名称是这样我就可以做进一步的研究?谢谢你。
I tried using a normal DateTime.Parse() with no luck. Does anyone know how to parse this, or if anything what the name of this format is so I can do further research? Thanks.
推荐答案
这是一个 UNIX时间戳 。使用此code到时间戳转换为的DateTime
目标:
It's a UNIX Timestamp. Use this code to convert the timestamp to a DateTime
object:
static DateTime ConvertFromUnixTimestamp(long timestamp)
{
return new DateTime(1970, 1, 1, 0, 0, 0, 0).AddSeconds(timestamp);
}
这篇关于解析在.NET返回JSON的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!