using System; using System.Collections; using System.Collections.Generic; using UnityEngine; /* 工具-时间处理 */ public class TimeUtil { //格式化,最终得出分和秒 public static string GetTimeStr(float time, bool ceil = true) { int seconds = ceil ? Mathf.CeilToInt(time) : Mathf.FloorToInt(time); string str = ""; int m = seconds / 60; if (m < 10) { str += 0; } str += m; str += " : "; int s = seconds % 60; if (s < 10) { str += 0; } str += s; return str; } public static string GetOfflineTimeStr(long offlineTime, bool online) { if (online) return TextAutoLanguage2.GetTextByKey("friend_offline-time_0"); long now = JC.CS.Utility.GetTimestamp(); long dt = now - offlineTime; if (dt < 0) dt = 0; if (offlineTime == 0) return TextAutoLanguage2.GetTextByKey("friend_offline-time_1"); long min = dt / (60 * 1000); if (min == 0) min += 1; if (min < 60) { return String.Format(TextAutoLanguage2.GetTextByKey("friend_offline-time_2"), min); } long hour = min / 60; if (hour < 24) { return String.Format(TextAutoLanguage2.GetTextByKey("friend_offline-time_3"), hour); } long day = hour / 24; if (day < 365) { return String.Format(TextAutoLanguage2.GetTextByKey("friend_offline-time_4"), day); } long year = day / 365; return String.Format(TextAutoLanguage2.GetTextByKey("friend_offline-time_5"), year); } }