Convert Timer Interval in seconds and minutes
Asked Answered
H

4

5

I can get in textbox the timer1 interval but it is in milliseconds how to convert in seconds or in minutes?

Henceforward answered 9/9, 2011 at 8:28 Comment(1)
divide it by 1000 or 60000...Cassella
S
9
var timeSpan = TimeSpan.FromMilliseconds(5000);

var seconds = timeSpan.TotalSeconds;
var minutes = timeSpan.TotalMinutes;
Silicon answered 9/9, 2011 at 8:31 Comment(1)
i have change 5000 in timer1.interval insert textbox1.text = seconds.tostring(); and work! thanks so muchCatacomb
X
1

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;
}
Xavier answered 9/9, 2011 at 8:30 Comment(0)
C
1

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;
        }
Chromic answered 9/9, 2011 at 8:32 Comment(0)
D
0

milliseconds to seconds

seconds = myMillisecondValue /1000;

milliseconds to minutes

minutes = myMillisecondValue /60000;
Desk answered 9/9, 2011 at 8:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.