TimeUtil.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. /* 工具-时间处理 */
  6. public class TimeUtil
  7. {
  8. //格式化,最终得出分和秒
  9. public static string GetTimeStr(float time, bool ceil = true)
  10. {
  11. int seconds = ceil ? Mathf.CeilToInt(time) : Mathf.FloorToInt(time);
  12. string str = "";
  13. int m = seconds / 60;
  14. if (m < 10) {
  15. str += 0;
  16. }
  17. str += m;
  18. str += " : ";
  19. int s = seconds % 60;
  20. if (s < 10)
  21. {
  22. str += 0;
  23. }
  24. str += s;
  25. return str;
  26. }
  27. public static string GetOfflineTimeStr(long offlineTime, bool online) {
  28. if (online) return TextAutoLanguage2.GetTextByKey("friend_offline-time_0");
  29. long now = JC.CS.Utility.GetTimestamp();
  30. long dt = now - offlineTime;
  31. if (dt < 0) dt = 0;
  32. if (offlineTime == 0) return TextAutoLanguage2.GetTextByKey("friend_offline-time_1");
  33. long min = dt / (60 * 1000);
  34. if (min == 0) min += 1;
  35. if (min < 60) {
  36. return String.Format(TextAutoLanguage2.GetTextByKey("friend_offline-time_2"), min);
  37. }
  38. long hour = min / 60;
  39. if (hour < 24) {
  40. return String.Format(TextAutoLanguage2.GetTextByKey("friend_offline-time_3"), hour);
  41. }
  42. long day = hour / 24;
  43. if (day < 365) {
  44. return String.Format(TextAutoLanguage2.GetTextByKey("friend_offline-time_4"), day);
  45. }
  46. long year = day / 365;
  47. return String.Format(TextAutoLanguage2.GetTextByKey("friend_offline-time_5"), year);
  48. }
  49. }