You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
986B

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. namespace TelpoPush.Common
  7. {
  8. public class TimeHelper
  9. {
  10. /// <summary>
  11. /// 时间戳转成时间类型
  12. /// </summary>
  13. /// <param name="timeStamp"></param>
  14. /// <returns></returns>
  15. public static DateTime ConvertToLocalDateTime(string timeStamp)
  16. {
  17. DateTime dtStart = TimeZoneInfo.ConvertTime(new DateTime(1970, 1, 1), TimeZoneInfo.Utc, TimeZoneInfo.Local);
  18. if (timeStamp.Length == 13)
  19. {
  20. long lTime = long.Parse(timeStamp + "0000");
  21. TimeSpan toNow = new TimeSpan(lTime);
  22. return dtStart.Add(toNow);
  23. }
  24. return dtStart.AddSeconds(long.Parse(timeStamp));
  25. }
  26. public static string ToDateTimeStr(DateTime dt)
  27. {
  28. return dt.ToString("yyyy-MM-dd HH:mm:ss");
  29. }
  30. }
  31. }