开发者

Convert Timer Interval in seconds and minutes

I can get in textbox the timer1 interval but it is in milliseconds how to convert开发者_如何学JAVA in seconds or in minutes?


var timeSpan = TimeSpan.FromMilliseconds(5000);

var seconds = timeSpan.TotalSeconds;
var minutes = timeSpan.TotalMinutes;


Check the TimeSpan Methods.

   public static double ConvertMillisecondsToSeconds(double milliseconds)
        {
        return TimeSpan.FromMilliseconds(milliseconds).TotalSeconds;
        }


    public static double ConvertMillisecondsToMinutes(double milliseconds)
        {
        return TimeSpan.FromMilliseconds(milliseconds).TotalMinutes;
        }


Make use of TimeSpan to do the work for you

C# Convert Milliseconds, Seconds, Minutes

Try

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;
}


milliseconds to seconds

seconds = myMillisecondValue /1000;

milliseconds to minutes

minutes = myMillisecondValue /60000;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜