倒计时 时分秒 转换(笔记小本本)

倒计时中总秒数转剩余小时、分钟、秒。

利用UniRX中的Sample操作符 实现一秒执行一次。

        Observable.EveryUpdate()
            .Where(_ => true)
            .Sample(TimeSpan.FromSeconds(1f))
//分界线  注释:下边 “Interval"的功能就是重复延时 等同于上边三行代码 
Observable.Interval(TimeSpan.FromSeconds(1f))
                  .Subscribe(_ =>
                  {  
                      //str_time  是分钟  首先 转换为秒
                      // 一分钟  = 60 秒
                      index_SUM_seconds--;
                       // 小时   
                      int index_hour = index_SUM_seconds / 3600;
                      //                     总分钟                     总小时            换成总秒数是换成总小时的秒数  换成分钟 就是换成总小时的分钟
                      int index_minutes = index_SUM_seconds / 60 - ((index_SUM_seconds / 3600) * 3600) / 60;
                      //                               总秒数                           总小时 换成 总小时的秒数   这个小时的分钟换成秒数
                      int index_seconds = index_SUM_seconds - ((index_hour * 3600) + (index_minutes * 60));
                      string str_Show = index_hour.ToString("00") + ":" + index_minutes.ToString("00") + ":" + index_seconds.ToString("00");
                      
                      Debug.Log(str_Show);
                  }).AddTo(this);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值