TimeComponent.cs 479 B

1234567891011121314151617181920212223242526272829303132
  1. using Model;
  2. namespace Model
  3. {
  4. /// <summary>
  5. /// 用于同步服务端和客户端时间
  6. /// </summary>
  7. public class TimeComponent: Component
  8. {
  9. private long syncTime;
  10. private long syncClientTime;
  11. public long SyncTime
  12. {
  13. get
  14. {
  15. return this.syncTime;
  16. }
  17. set
  18. {
  19. this.syncTime = value;
  20. this.syncClientTime = TimeHelper.ClientNow();
  21. }
  22. }
  23. public long Now()
  24. {
  25. return TimeHelper.ClientNow() - this.syncClientTime + syncTime;
  26. }
  27. }
  28. }