C# DateTime毫秒字符串互转

/// <summary>
/// 起始时间
/// </summary>
DateTime TIME_START = new DateTime(1970, 1, 1);

//毫秒string转DateTime
UInt64 timeVal;
if (!string.IsNullOrEmpty(strDate))
{
    timeVal = UInt64.Parse(strDate);
    strDate = DateTime.Parse(TIME_START.ToString()).AddMilliseconds(timeVal);
}

//DateTime转毫秒string
UInt64 timeVal = (UInt64)(time - TIME_START).TotalMilliseconds;
            
strDate = (timeVal  > UInt64.MaxValue || timeVal  < UInt64.MinValue) ? 0 : timeVal.ToString();

猜你喜欢

转载自blog.csdn.net/qq_35106907/article/details/84224204
今日推荐