시간초 받아와서 시:분:초 로 변환

유니티 C# 2020. 11. 30. 15:02

출처: answer-id.com/ko/50836580

 

TimeSpan t = TimeSpan.FromSeconds( secs );

string answer = string.Format("{0:D2}h:{1:D2}m:{2:D2}s:{3:D3}ms",

                      t.Hours,

                      t.Minutes,

                      t.Seconds,

                      t.Milliseconds);

 

 

또는

TimeSpan time = TimeSpan.FromSeconds(seconds);

 

//here backslash is must to tell that colon is

//not the part of format, it just a character that we want in output

string str = time .ToString(@"hh\:mm\:ss\:fff");