12345678910111213141516171819202122232425262728293031 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class TimeUtils
- {
- /// <summary>
- /// 将 DateTime时间格式转换为Unix时间戳格式
- /// </summary>
- /// <param name="time">时间</param>
- /// <returns>long</returns>
- 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;
- }
- /// <summary>
- /// 将Unix时间戳格式 转换为DateTime时间格式
- /// </summary>
- /// <param name="time">时间</param>
- /// <returns>long</returns>
- 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;
- }
- }
|