我可以在文本框中输入timer1间隔,但是以毫秒为单位的转换时间是以秒为单位还是以分钟为单位?
答案 0 :(得分:9)
var timeSpan = TimeSpan.FromMilliseconds(5000);
var seconds = timeSpan.TotalSeconds;
var minutes = timeSpan.TotalMinutes;
答案 1 :(得分:1)
利用TimeSpan
为您完成工作
C# Convert Milliseconds, Seconds, Minutes
尝试
public string getFormattedTimeFromMilliSecond(double milliSecond)
{
TimeSpan t = TimeSpan.FromMilliseconds(milliSecond);
string formatedTime = string.Format("{0:D2}H:{1:D2}M:{2:D2}S",
t.Hours,
t.Minutes,
t.Seconds);
return formatedTime;
}
答案 2 :(得分:1)
public static double ConvertMillisecondsToSeconds(double milliseconds)
{
return TimeSpan.FromMilliseconds(milliseconds).TotalSeconds;
}
public static double ConvertMillisecondsToMinutes(double milliseconds)
{
return TimeSpan.FromMilliseconds(milliseconds).TotalMinutes;
}
答案 3 :(得分:0)
毫秒到秒
seconds = myMillisecondValue /1000;
毫秒到分钟
minutes = myMillisecondValue /60000;