Clock board
A board that shows the date and time in UTC and in the player's time zone, a countdown to the next daily reset
(midnight UTC) and the local player's worldPlayerId. It updates once a second.
Put it on a TextMeshPro label. See Date and time.
ClockBoard.cs
using StageTime.SDK;
using TMPro;
/// <summary>
/// A board that shows today's date and time in UTC and in the player's time zone, a countdown to the next daily reset
/// (midnight UTC), and the local player's id for this world. Shows <c>STTime</c> and <c>worldPlayerId</c>.
/// </summary>
public class ClockBoard : StageTimeBehaviour
{
public TMP_Text label;
private int lastSecond = -1;
private void Update()
{
double now = STTime.utcNow;
int second = STTime.Second(now);
if (second == lastSecond) return; // update once a second
lastSecond = second;
Refresh(now);
}
public void Refresh(double now)
{
if (label == null) return;
double local = now + STTime.localUtcOffsetHours * 3600.0;
double nextReset = (STTime.utcDay + 1) * 86400.0;
int left = (int)(nextReset - now);
string id = Networking.LocalPlayer != null ? Networking.LocalPlayer.worldPlayerId : "";
label.text = $"UTC {STTime.ToIsoString(now)}\n"
+ $"Local {Two(STTime.Hour(local))}:{Two(STTime.Minute(local))} ({Weekday(STTime.DayOfWeek(local))})\n"
+ $"Daily reset in {left / 3600}h {Two(left % 3600 / 60)}m\n"
+ $"Day #{STTime.utcDay} · {(STTime.isServerTime ? "server time" : "device time")}\n"
+ $"Your id here: {(id.Length > 8 ? id.Substring(0, 8) + "…" : id)}";
}
private string Two(int value) => value < 10 ? "0" + value : value.ToString();
private string Weekday(int day)
{
switch (day)
{
case 0: return "Sunday";
case 1: return "Monday";
case 2: return "Tuesday";
case 3: return "Wednesday";
case 4: return "Thursday";
case 5: return "Friday";
default: return "Saturday";
}
}
}