Unity游戏开发倒计时

DateTime currentTime=new DateTime(currentyear,currentMonth,currentDay,currentHour,currentMinute,currentSecond);

DateTime lastProducetTime=new DateTime(lastproductYear,lastproductfoodMonth,lastproductfoodDay,lastproductfoodHour,lastproductfoodMinute,lastproductfoodSecond);

600-(((int)((currentTime - lastProducetTime).TotalSeconds))%600);

StartCoroutine("CountDown", GameInfomation.foodProductime);


     //倒计时//
    public IEnumerator CountDown(int m)  //m为倒计时总时长,计算单位为秒
    {
        hourCountDown = (int)m / 3600;//计算小时数
        minuteCountDown = ((int)m - hourCountDown * 3600) / 60;//计算分钟数
        secondCountDown = (int)m - hourCountDown * 3600 - minuteCountDown * 60;//计算秒数
        countDown.text = string.Format("{1:d2}:{2:d2}", hourCountDown, minuteCountDown, secondCountDown);//显示倒计时

        while (m > 0)
        {
            yield return new WaitForSeconds(1);
            m--;
            hourCountDown = (int)m / 3600;//计算小时数   //1
            minuteCountDown = ((int)m - hourCountDown * 3600) / 60;//计算分钟数   //56
            secondCountDown = (int)m - hourCountDown * 3600 - minuteCountDown * 60;//计算秒数
            countDown.text = string.Format("{1:d2}:{2:d2}", hourCountDown, minuteCountDown, secondCountDown);//显示倒计时
        }
        m = 0;
    }


FR: 海涛高软(Hunk Xu)

你可能感兴趣的:(date日期)