using System; using System.Collections.Generic; using System.Text; namespace IStation.Untity { //1秒等于1000毫秒=1000微妙=1000毫微秒 ticks的单位是100毫微秒 public class DateTimeTransfer { /// /// 从1970年1月1日0时开始的秒数 包含时区 /// /// /// public static DateTime FromSeconds(long seconds) { var defaultTime = new DateTime(1970, 1, 1, 8, 0, 0); var timeTicks = defaultTime.Ticks + seconds * 10000000; return new DateTime(timeTicks); } public static long ToSeconds(DateTime dt) { var defaultTime = new DateTime(1970, 1, 1, 8, 0, 0); var seconds = (dt - defaultTime).TotalSeconds; return (long)seconds; } } }