powerfun-unity/Assets/Scripts/Utils/CustomDateTime.cs

32 lines
758 B
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// 跟服务器端同步的时间对象
/// </summary>
public class CustomDateTime
{
long StartingTime = Stopwatch.GetTimestamp();
private DateTime _dateTime;
public CustomDateTime(DateTime dateTime)
{
_dateTime = dateTime;
}
public DateTime GetDateTime()
{
//Console.WriteLine(Stopwatch.IsHighResolution);
long endingTime = Stopwatch.GetTimestamp();
long ElapsedTime = endingTime - StartingTime;
double ElapsedSeconds = ElapsedTime * (1.0 / Stopwatch.Frequency);
return _dateTime.AddSeconds(ElapsedSeconds);
}
}