Created
February 21, 2018 15:54
-
-
Save glebov21/6a7a2427cadbac8bbc14f5e8dc29705a to your computer and use it in GitHub Desktop.
time left string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string GetTimeLeftString(this TimeSpan timeLeft) | |
{ | |
var ts = timeLeft; | |
if (ts.TotalSeconds < 0) | |
return "..."; | |
var result = string.Format("{0}:{1}", ts.Minutes.ToString("00"), ts.Seconds.ToString("00")); | |
if (timeLeft.TotalHours > 1d) | |
result = ts.Hours.ToString("00") + ":" + result; | |
if (timeLeft.TotalDays > 1d) | |
result = Mathf.FloorToInt((float)ts.TotalDays) + " " + UnityUtils.Localize("Common.Days") + " " + result; | |
return result; | |
} | |
public static string GetTimeLeftString(this double secondsLeft) | |
{ | |
var ts = DateTime.Now.AddSeconds(secondsLeft) - DateTime.Now; | |
return GetTimeLeftString(ts); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment