| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- 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 "在线";
- long now = JC.CS.Utility.GetTimestamp();
- long dt = now - offlineTime;
- if (dt < 0) dt = 0;
- if (offlineTime == 0) return "离线";
- long min = dt / (60 * 1000);
- if (min == 0) min += 1;
- if (min < 60) {
- return min + "分钟前";
- }
- long hour = min / 60;
- if (hour < 24) {
- return hour + "小时前";
- }
- long day = hour / 24;
- if (day < 365) {
- return day + "天前";
- }
- long year = day / 365;
- return year + "年前";
- }
- }
|