time.text = System.DateTime.Now.ToString("HH:mm");
date.text = System.DateTime.Now.ToString("yyyy年MM月dd日");
timeText.text = System.DateTime.Now.ToString("HH:mm");
dateText.text = System.DateTime.Now.ToString("yyyy/MM/dd dddd", new System.Globalization.CultureInfo("zh-cn"));
// dateText.text = System.DateTime.Now.ToString("dddd", new System.Globalization.CultureInfo("zh-cn"));
==================
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Timertt : MonoBehaviour {
private Text timer;//时间
//private float time;//游戏已经运行时间
private float startTime;//游戏开始的时间
void Start () {
timer = transform.Find("Timer").GetComponent<Text>();
//得到游戏开始的时间;单位:秒
startTime = Time.time;
}
void Update () {
//游戏已经运行的时间=当前游戏时间跟游戏开始的时间的差,单位:秒
float time = Time.time - startTime;
//秒
int seconds=(int)(time%60);
//分
int minutes = (int)(time/60);
//游戏已经运行时间
string strTime = string.Format("{0:00}:{1:00}",minutes,seconds);
timer.text = strTime;
}
}
网友评论