C#時間戳轉換
阿新 • • 發佈:2017-06-01
mes cond etime int timezone cal 時間戳轉換 zone alt
時間戳轉DateTime
timestamp為10位秒級* 10000000,若為13位毫秒級*10000。
private DateTime TimestampToDateTime(long timestamp)
{
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970,1,1));
long lTime = timestamp * 10000000;
TimeSpan nowTimeSpan = new TimeSpan(lTime);
DateTime resultDateTime = dateTimeStart.Add(nowTimeSpan);
return resultDateTime;
}
DateTime轉時間戳
秒級
private int DateTimeToTimestamp(DateTime time)
{
DateTime startDateTime = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(197, 1, 1));
return Convert.ToInt32((time - startDateTime).TotalSeconds);
}
C#時間戳轉換