2021-03-25 12:55:52 +08:00
|
|
|
/************************************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* Copyright (c) 2018 - 2021 monitor1394 */
|
|
|
|
|
/* https://github.com/monitor1394 */
|
|
|
|
|
/* */
|
|
|
|
|
/************************************************/
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace XCharts
|
|
|
|
|
{
|
|
|
|
|
public static class DateTimeUtil
|
|
|
|
|
{
|
2021-04-22 18:55:56 +08:00
|
|
|
private static readonly DateTime k_DateTime1970 = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Local);
|
2021-03-25 12:55:52 +08:00
|
|
|
|
|
|
|
|
public static int GetTimestamp()
|
|
|
|
|
{
|
|
|
|
|
return (int)(DateTime.Now - k_DateTime1970).TotalSeconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int GetTimestamp(DateTime time)
|
|
|
|
|
{
|
|
|
|
|
return (int)(time - k_DateTime1970).TotalSeconds;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static DateTime GetDateTime(int timestamp)
|
|
|
|
|
{
|
|
|
|
|
long span = ((long)timestamp) * 10000000;
|
|
|
|
|
return k_DateTime1970.Add(new TimeSpan(span));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|