通过秒数 实现 时间的格式化显示成 00:00:00 格式 实现,一般用于做倒计时刷新用
代码参考:
public static string clockFormat(int time, bool isShowH = false)
{
if (time < 0) time = 0;
int hours = (int)Mathf.Floor(time / 3600);
int minutes = (int)Mathf.Floor((time - hours * 3600) / 60);
int seconds = time % 60;
string hourStr = hours < 10 ? "0" + hours : "" + hours;
string minStr = minutes < 10 ? "0" + minutes : "" + minutes;
string secStr = seconds < 10 ? "0" + seconds : "" + seconds;
if (isShowH)
{
return hourStr + ":" + minStr + ":" + secStr;
}
else
{
return minStr + ":" + secStr;
}
}
|