I can get in textbox the timer1 interval but it is in milliseconds how to convert in seconds or in minutes?
Convert Timer Interval in seconds and minutes
var timeSpan = TimeSpan.FromMilliseconds(5000);
var seconds = timeSpan.TotalSeconds;
var minutes = timeSpan.TotalMinutes;
i have change 5000 in timer1.interval insert textbox1.text = seconds.tostring(); and work! thanks so much –
Catacomb
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;
}
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;
}
milliseconds to seconds
seconds = myMillisecondValue /1000;
milliseconds to minutes
minutes = myMillisecondValue /60000;
© 2022 - 2024 — McMap. All rights reserved.