时间戳转为C#格式时间

常常发现不少地方使用一个时间戳表示时间。好比: 1370838759 表示 2013年6月10日 12:32:39。 咱们就须要一个工具,方便地转换这种时间格式markdown

什么是时间戳?工具

时间戳, 又叫Unix Stamp. 从1970年1月1日(UTC/GMT的午夜)开始所通过的秒数,不考虑闰秒。post

如:
{
"pubTime":1443801600000,
"value":54
},
{
"pubTime":1443888000000,
"value":137
},
{
"pubTime":1443974400000,
"value":262
},
{
"pubTime":1444060800000,
"value":334
},spa

这种1443801600000 的值 怎么转换为对应的时间??code


// 时间戳转为C#格式时间
private DateTime StampToDateTime(string time)
{blog

time = time.Substring(0, 10); double timestamp = Convert.ToInt64(time); System.DateTime dateTime = new System.DateTime(1970, 1, 1, 0, 0, 0, 0); dateTime = dateTime.AddSeconds(timestamp).ToLocalTime(); return dateTime; }

调用:StampToDateTime("1443801600000");string

fffffffffffffffff
test red font.
相关文章
相关标签/搜索