Unity 判断两次时间间隔

来源:互联网 发布:mysql truncate 编辑:程序博客网 时间:2024/06/04 18:28
using System;using UnityEngine;public class TimeMessage : MonoBehaviour{//储存第一次的时间    public void SetDateTime()     {//使用了PlayerPrefs    获取的时候一样        PlayerPrefs.SetString("SetTime", DateTime.Now.ToShortTimeString());     }    // 判断第一次和现在的时间间隔    public void GetDateTime()    {              DateTime nowTime = DateTime.Now;        DateTime oldTime = DateTime.Parse(PlayerPrefs.GetString("SetTime"));        TimeSpan timeSpan = nowTime - oldTime;        //判断上次储存的时间        if (timeSpan.Days > 1)         {                       Debug.Log("Days: "+ timeSpan.Days);        }        else if (timeSpan.Hours > 1)        {                       Debug.Log("Hours: " + timeSpan.Hours);        }        else if (timeSpan.Minutes < 60)        {            Debug.Log("Minutes: " + timeSpan.Minutes);        }          }}

原创粉丝点击