钉钉对接接口

Common.cs 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. namespace DingDingDemo.Common
  5. {
  6. public static class Common
  7. {
  8. /// <summary>
  9. /// 获取时间戳
  10. /// </summary>
  11. /// <returns></returns>
  12. public static string GetTimeStamp(System.DateTime time)
  13. {
  14. long ts = ConvertDateTimeToInt(time);
  15. return ts.ToString();
  16. }
  17. /// <summary>
  18. /// 将c# DateTime时间格式转换为Unix时间戳格式
  19. /// </summary>
  20. /// <param name="time">时间</param>
  21. /// <returns>long</returns>
  22. public static long ConvertDateTimeToInt(System.DateTime time)
  23. {
  24. System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1, 0, 0, 0, 0));
  25. long t = (time.Ticks - startTime.Ticks) / 10000; //除10000调整为13位
  26. return t;
  27. }
  28. /// <summary>
  29. /// 时间戳转为C#格式时间
  30. /// </summary>
  31. /// <param name=”timeStamp”></param>
  32. /// <returns></returns>
  33. private static DateTime ConvertStringToDateTime(string timeStamp)
  34. {
  35. DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
  36. long lTime = long.Parse(timeStamp + "0000");
  37. TimeSpan toNow = new TimeSpan(lTime);
  38. return dtStart.Add(toNow);
  39. }
  40. }
  41. }