C#时间转换UInt64<--->DateTime

来源:互联网 发布:能做网站编程单位 编辑:程序博客网 时间:2024/05/22 00:20



C#时间转换UInt64<--->DateTime


DateTime---> UInt64


DateTime currentDateTime = new DateTime();
System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
UInt64 time = (UInt64)(currentDateTime - startTime).TotalMilliseconds;
--------------------------------------------------------------------------------
UInt64--->DateTime


static DateTime dt1970 = new System.DateTime(1970, 1, 1, 0, 0, 0);
        public static DateTime ConvertLongToDateTime(UInt64 d)
        {
            System.DateTime time = System.DateTime.MinValue;
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(dt1970);
            time = startTime.AddMilliseconds(d);
            return time;
        }

0 0
原创粉丝点击