c# DateTime时间格式和JAVA时间戳格式相互转换

时间:2021-07-24 02:34:10
/// java时间戳格式时间戳转为C#格式时间  
public static DateTime GetTime(long timeStamp)
{
DateTime dtStart
= TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = timeStamp * 10000;
TimeSpan toNow
= new TimeSpan(lTime);
return dtStart.Add(toNow);
}

/// C# DateTime时间格式转换为Java时间戳格式
public static long ConvertDateTime(System.DateTime time)
{
System.DateTime startTime
= TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1));
return (long)(time - startTime).TotalMilliseconds;
}