TimeHelper.cs 642 B

1234567891011121314151617181920212223242526272829
  1. using System;
  2. namespace WS
  3. {
  4. ///<summary>时间处理帮助类</summary>
  5. public static class TimeHelper
  6. {
  7. private static readonly long epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).Ticks;
  8. public static readonly DateTime epochTime = new DateTime(1970, 1, 1, 0, 0, 0);
  9. /// <summary>时间戳 (毫秒)</summary>
  10. public static long ClientNow()
  11. {
  12. return (DateTime.UtcNow.Ticks - epoch) / 10000;
  13. }
  14. /// <summary>时间戳 (秒)</summary>
  15. public static long ClientNowSeconds()
  16. {
  17. return (DateTime.UtcNow.Ticks - epoch) / 10000000;
  18. }
  19. public static long Now()
  20. {
  21. return ClientNow();
  22. }
  23. }
  24. }