using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class CurrentTime : MonoBehaviour { private Text CurrrentTimeText; private int hour; private int minute; private int second; private int year; private int month; private int day; // Start is called before the first frame update void Start() { CurrrentTimeText = GetComponent(); } // Update is called once per frame void Update() { //获取当前时间 hour = DateTime.Now.Hour; minute = DateTime.Now.Minute; second = DateTime.Now.Second; year = DateTime.Now.Year; month = DateTime.Now.Month; day = DateTime.Now.Day; //格式化显示当前时间 CurrrentTimeText.text = string.Format("{0:D2}年{1:D2}月{2:D2}日" +" "+ "{3:D2}:{4:D2}:{5:D2}", year, month, day, hour, minute, second); } }