先看效果

代码如下
cs
private IEnumerator ShowTimer()
{
while (true)
{
yield return new WaitForSeconds(1f);
DateTime currentDateTime = DateTime.Now;
// 获取星期几的中文名称
string dayOfWeek = currentDateTime.ToString("dddd", new CultureInfo("zh-CN"));
// 格式化时间
string formattedDate = currentDateTime.ToString("yyyy年M月d日 ") + dayOfWeek + " " +
currentDateTime.ToString("HH:mm:ss");
timer.text = formattedDate;
}
}
// StartCoroutine(ShowTimer());开启该协程