前言
在存储图片的时候使用时间戳可以很好的管理图片名称。
源码
public static long ConvertDateTimep(DateTime time)
{
return ((time.ToUniversalTime().Ticks - 621355968000000000) / 10000000);
}
public static DateTime GetTime(string timeStamp)
{
if (timeStamp.Length > 10)
{
timeStamp = timeStamp.Substring(0, 10);
}
DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
long lTime = long.Parse(timeStamp + "0000000");
TimeSpan toNow = new TimeSpan(lTime);
return dateTimeStart.Add(toNow);
}
效果
long unixTime = TimeTool.ConvertDateTimep(DateTime.Now);
Debug.Log(unixTime);
Debug.Log(TimeTool.GetTime(unixTime.ToString()).ToString());
Debug.Log(TimeTool.GetTime(unixTime.ToString()).Year);
Debug.Log(TimeTool.GetTime(unixTime.ToString()).Month);
Debug.Log(TimeTool.GetTime(unixTime.ToString()).Day);
Debug.Log(TimeTool.GetTime(unixTime.ToString()).Hour);
Debug.Log(TimeTool.GetTime(unixTime.ToString()).Minute);
Debug.Log(TimeTool.GetTime(unixTime.ToString()).Second);
|