将秒数转为“00:00:00”,将“00:00:00”转为秒数
将秒数转为00:00:00
1 /// <summary> 2 /// 将秒数转为00:00:00 3 /// </summary> 4 /// <param name="l">传过来的秒数</param> 5 /// <returns>返回00:00:00格式的字符串</returns> 6 public static String GetTime(int l) 7 { 8 int hour = 0; 9 int minute = 0; 10 int second = 0; 11 second = l / 1000; 12 13 if (second > 60) 14 { 15 minute = second / 60; 16 second = second % 60; 17 } 18 if (minute > 60) 19 { 20 hour = minute / 60; 21 minute = minute % 60; 22 } 23 return (hour.ToString() + ":" + minute.ToString() + ":" 24 + second.ToString()); 25 }
将00:00:00转为秒数
1 // <summary> 2 /// 将00:00:00转为秒数 3 /// </summary> 4 /// <param name="s">00:00:00格式的字符串</param> 5 /// <returns>返回int 类型的秒数</returns> 6 public static int cdate(string s) 7 { 8 DateTime dt = Convert.ToDateTime(s); 9 int time = (Convert.ToInt32(dt.Hour) * 3600) + (Convert.ToInt32(dt.Minute) * 60) + Convert.ToInt32(dt.Second); 10 return time; 11 }