51 lines
1.1 KiB
C#
51 lines
1.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
// 获取时间并显示
|
|
|
|
public class TimeDisplay : MonoBehaviour
|
|
{
|
|
// 时间
|
|
public TextMeshProUGUI timeText;
|
|
// 日期
|
|
// public Text dateText;
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
/*// 获取当前日期
|
|
DateTime currentDate = DateTime.Now;
|
|
|
|
// 将日期转换为字符串
|
|
string dateString =currentDate.ToString("yyyy-MM-dd");
|
|
|
|
// 将日期显示在 Text 组件中
|
|
if (dateText != null)
|
|
{
|
|
dateText.text = dateString;
|
|
}*/
|
|
|
|
|
|
// 获取当前时间
|
|
DateTime currentTime = DateTime.Now;
|
|
|
|
// 将时间转换为字符串
|
|
string timeString = currentTime.ToString("HH:mm:ss");
|
|
|
|
// 将时间显示在 Text 组件中
|
|
if (timeText != null)
|
|
{
|
|
timeText.text = timeString;
|
|
}
|
|
}
|
|
}
|