SysConfig.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Security.Policy;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. public static class SysConfig
  9. {
  10. public static DateTime ToUtc(this DateTime time)
  11. {
  12. return time.AddHours(-AppConfigHelper.Get("TimeZone", 8));
  13. }
  14. public static DateTime ToLocal(this DateTime utcTime)
  15. {
  16. return utcTime.AddHours(AppConfigHelper.Get("TimeZone", 8));
  17. }
  18. public static DateTimeOffset ToLocal(this DateTimeOffset utcTime)
  19. {
  20. return utcTime.ToOffset(TimeSpan.FromHours(AppConfigHelper.Get("TimeZone", 8)));
  21. }
  22. public static string GetBaseUrl()
  23. {
  24. return $"http://{IpHelper.GetLocalIp()}:{AppConfigHelper.Get("HttpPort", 8090)}/api/";
  25. }
  26. public static string GetUrl(string url)
  27. {
  28. if (url.StartsWith("/"))
  29. {
  30. return $"http://{IpHelper.GetLocalIp()}:{AppConfigHelper.Get("HttpPort", 8090)}/api{url}";
  31. }
  32. else
  33. {
  34. return $"http://{IpHelper.GetLocalIp()}:{AppConfigHelper.Get("HttpPort", 8090)}/api/{url}";
  35. }
  36. }
  37. }