ASP.net C#解析INT的日期时间 [英] ASP.net c# Parse int as datetime

查看:127
本文介绍了ASP.net C#解析INT的日期时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定一个时间:




1286294501433




表示自1970年以来通过毫秒,我们如何将其转换为一个DateTime数据类型? EG:

  TRANSACTIONTIME =1286294501433 
UINT64 intTransTime = UInt64.Parse(TRANSACTIONTIME);
的DateTime transactionActualDate = DateTime.Parse(intTransTime.ToString());



抛出:




字符串未被识别为有效
日期时间。




请注意,所有时间传递到这个功能是保证是的之后的1970年。


解决方案

  VAR DT =新的datetime (1970,1,1).AddMilliseconds(1286294501433); 

您可能还需要指定 DateTimeKind 明确地说,根据您的具体要求:

  VAR DT =新的日期时间(1970年,1,1,0,0,0, DateTimeKind.Utc)
.AddMilliseconds(1286294501433);


Given a time:

1286294501433

Which represents milliseconds passed since 1970, how do we convert this to a DateTime data type? EG:

transactionTime = "1286294501433";
UInt64 intTransTime = UInt64.Parse(transactionTime);
DateTime transactionActualDate = DateTime.Parse(intTransTime.ToString());

Throws:

String was not recognized as a valid DateTime.

Please note all times passed into this function are guaranteed to be after 1970.

解决方案

var dt = new DateTime(1970, 1, 1).AddMilliseconds(1286294501433);

You might also need to specify the DateTimeKind explicitly, depending on your exact requirements:

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

这篇关于ASP.net C#解析INT的日期时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆