C# TimeSpan

using System;
using UnityEngine;

TimeSpan timeSpan=TimeSpan.FromSeconds(10000);//10000秒
Debug.LogFormat("{0} {1} {2}",timeSpan.Hours,timeSpan.Minutes,timeSpan.Seconds);//output: 2 46 40
Debug.Log(timeSpan.ToString());//output: 02:46:40
Debug.Log(timeSpan.ToString(@"hh:mm:ss"));//output: 02:46:40
Debug.Log(timeSpan.ToString(@"mm:ss"));//output: 46:40

//加减时间
timeSpan=timeSpan.Add(TimeSpan.FromSeconds(1));
Debug.Log(timeSpan.ToString(@"mm:ss"));//output: 46:41
timeSpan=timeSpan.Add(TimeSpan.FromSeconds(-2));
Debug.Log(timeSpan.ToString(@"mm:ss"));//output: 46:39

更多字符串的格式

原文地址:https://www.cnblogs.com/kingBook/p/13857507.html