TimeComponent.cs 516 B

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