Unity 时间相关

        /// <summary>
        /// 获得本地时间戳毫秒
        /// </summary>
        /// <returns></returns>
        public static long GetTime() {
            return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
        }

        /// <summary>
        /// 获得本地时间戳秒
        /// </summary>
        /// <returns></returns>
        public static long GetTim()
        {
            return (DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000000;
        }

        /// <summary>
        /// 传一个时间戳得一个经过时间
        /// </summary>
        /// <param name="timer">毫秒</param>
        /// <returns></returns>
        public static string GetTimer(string timer)
        {
            long ti = GetTime() - long.Parse(timer);
            if (ti / 60000 >= 1)
            {
                if (ti / 3600000 >= 1)
                {
                    if (ti / 86400000 >= 1)
                    {
                        int num = (int)(ti / 86400000);
                        return num + "天以前";
                    }
                    else
                    {
                        int num = (int)(ti / 3600000);
                        return num + "小时以前";
                    }
                }
                else
                {
                    int num = (int)(ti / 60000);
                    return num + "分钟以前";
                }
            }
            else
            {
                return "刚刚";
            }
        }

        /// <summary>
        /// 传入一个秒数返回字符串时间格式
        /// </summary>
        /// <param name="timer"></param>
        /// <returns></returns>
        public static string GetStrTimer(long timer, string typ)
        {
            string st = "";
            if (typ == "00:00")
            {
                if (timer > 60)
                {
                    int second = (int)(timer % 60);
                    int minute = (int)((timer - second) / 60);
                    string str;
                    if (minute >= 10)
                    {
                        str = minute.ToString();
                    }
                    else
                    {
                        str = "0" + minute.ToString();
                    }
                    if (second >= 10)
                    {
                        return str + ":" + second;
                    }
                    else
                    {
                        return str + ":00";
                    }
                }
                else
                {
                    if (timer >= 10)
                    {
                        return "00:" + timer;
                    }
                    else
                    {
                        return "00:0" + timer;
                    }
                }
            }
            else if (typ == "00:00:00")
            {

            }
            return st;
        }

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小张不爱写代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值