HKMBFZ/Assets/Scripts/Szz_Scripts/SetSystemTime.cs

41 lines
981 B
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class SetSystemTime : MonoBehaviour
{
public bool timeBefore;
public TextMeshProUGUI timebeforeText;
public TextMeshProUGUI timeAfterText;
// Start is called before the first frame update
void Start()
{
if (timeBefore)
StartCoroutine(GetTimeBefore());
else
StartCoroutine(GetTimeAfter());
}
IEnumerator GetTimeBefore()
{
while (true)
{
System.DateTime now=System.DateTime.Now;
timebeforeText.text = now.ToString("HH:mm:ss yyyy/MM/dd");
yield return new WaitForSeconds(1f);
}
}
IEnumerator GetTimeAfter()
{
while (true)
{
System.DateTime now = System.DateTime.Now;
timeAfterText.text = now.ToString("yyyy-MMM-dd HH:mm:ss");
yield return new WaitForSeconds(1f);
}
}
}