GPS下来的时间是“1481267203000”
搜了一下,得到的结果是
int i = 1481267203000;
i = 1481267203000 / 1000;
DateTime t = new DateTime(1970, 1, 1).AddSeconds(i);
后来写的方法
using System;
public class ConvertDataTimeHelper
{
/// <summary>
/// 将DateTime类型转换为long类型
/// </summary>
/// <param name="dt">时间</param>
/// <returns></returns>
public static long ConvertDataTimeLong(DateTime dt)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
TimeSpan toNow = DateTime.Now.Subtract(dtStart);
long timeStamp = toNow.Ticks;
timeStamp = long.Parse(timeStamp.ToString().Substring(0, timeStamp.ToString().Length - 7));
return timeStamp;
}
/// <summary>
/// 将Long类型转换为DateTime类型
/// </summary>
/// <param name="d">long</param>
/// <returns></returns>
public static DateTime ConvertLongDateTime(long d)
{
DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(d + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
DateTime dtResult = dtStart.Add(toNow);
return dtResult;
}
}
是不是北京时间就不知道了