using System; using System.Collections; using System.Collections.Generic; using UnityEngine; public class TimeUtils { /// /// 将 DateTime时间格式转换为Unix时间戳格式 /// /// 时间 /// long public static long ConvertToTimeStamp(DateTime time) { System.DateTime Time = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); long TimeStamp = (time.Ticks - Time.Ticks) / 10000; //除10000调整为13位 return TimeStamp; } /// /// 将Unix时间戳格式 转换为DateTime时间格式 /// /// 时间 /// long public static DateTime ConvertToDateTime(long time) { System.DateTime Time = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0)); DateTime dateTime = Time.AddMilliseconds(time); return dateTime; } }