public static string getTime(DateTime time, TIME_DISPLAY display) { if (display == TIME_DISPLAY.TD_HMSM_0) { return(time.Hour + ":" + time.Minute + ":" + time.Second + ":" + time.Millisecond); } else if (display == TIME_DISPLAY.TD_HMS_2) { return(intToString(time.Hour, 2) + ":" + intToString(time.Minute, 2) + ":" + intToString(time.Second, 2)); } else if (display == TIME_DISPLAY.TD_DHMS_ZH) { return(time.Hour + "时" + time.Minute + "分" + time.Second + "秒"); } return(""); }
public static string getTime(int timeSecond, TIME_DISPLAY display) { int min = timeSecond / 60; int second = timeSecond % 60; int hour = min / 60; if (display == TIME_DISPLAY.TD_HMSM_0) { return(hour + ":" + min + ":" + second); } else if (display == TIME_DISPLAY.TD_HMS_2) { return(intToString(hour, 2) + ":" + intToString(min, 2) + ":" + intToString(second, 2)); } else if (display == TIME_DISPLAY.TD_DHMS_ZH) { int totalMin = timeSecond / 60; int totalHour = totalMin / 60; int totalDay = totalHour / 24; int curHour = totalHour % 24; int curMin = totalMin % 60; int curSecond = timeSecond % 60; // 大于等于1天 if (totalDay > 0) { return(totalDay + "天" + curHour + "时" + curMin + "分" + curSecond + "秒"); } // 小于1天,并且大于等于1小时 else if (totalHour > 0) { return(totalHour + "时" + curMin + "分" + curSecond + "秒"); } // 小于1小时,并且大于等于1分钟 else if (totalMin > 0) { return(totalMin + "分" + curSecond + "秒"); } return(timeSecond + "秒"); } return(""); }
public static string getTime(TIME_DISPLAY display) { return(getTime(DateTime.Now, display)); }