示例#1
0
 public static string ToShortTimeString(
     this TimeSpan timeSpan)
 {
     if (timeSpan.TotalMinutes <= 1)
     {
         int seconds = HDMath.Round(timeSpan.TotalSeconds);
         return(string.Format("{0} sec{1}", seconds, seconds > 1 ? "s" : ""));
     }
     else if (timeSpan.TotalHours <= 1)
     {
         int mins = (int)timeSpan.TotalMinutes;
         int secs = timeSpan.Seconds;
         return(string.Format("{0} min{1} {2} sec{3}", mins, mins > 1 ? "s" : "", secs, secs > 1 ? "s" : ""));
     }
     else if (timeSpan.TotalDays <= 1)
     {
         int hours = (int)timeSpan.TotalHours;
         int mins  = timeSpan.Minutes;
         return(string.Format("{0} hour{1} {2} min{3}", hours, hours > 1 ? "s" : "", mins, mins > 1 ? "s" : ""));
     }
     else
     {
         int days  = (int)timeSpan.TotalDays;
         int hours = timeSpan.Hours;
         return(string.Format("{0} day{1} {2} hour{3}", days, days > 1 ? "s" : "", hours, hours > 1 ? "s" : ""));
     }
 }
示例#2
0
 public static float Round128(this float value)
 {
     return(HDMath.Round(value * 128f) * (1f / 128f));
 }