using UnityEngine;
using System.Collections;
using System;
public class TimeManager
{
//和服务器时间错的差距
static int gapTimeWithServer;
//获得秒级单位的时间戳
public static int GetEpoch()
{
TimeSpan t = ( DateTime.UtcNow - new DateTime( 1970, 1, 1 ) );
int timestamp = (int)t.TotalSeconds;
return timestamp;
}
//获得毫秒级别单位的时间戳
public static double GetEpochMill()
{
TimeSpan t = ( DateTime.UtcNow - new DateTime( 1970, 1, 1 ) );
return t.TotalMilliseconds;
}
public static int GetEpochSyn()
{
return TimeManager.GetEpoch() + TimeManager.gapTimeWithServer;
}
public static int SetTimeSynServer( int timeServer )
{
int timeClient = TimeManager.GetEpoch();
gapTimeWithServer = timeServer - timeClient;
return TimeManager.gapTimeWithServer;
}
public static int GetFitureSyn( int time )
{
int gap = time - GetEpochSyn();
if( gap < 0 )
{
gap = 0;
}
return gap;
}
}