I'm trying to convert seconds to hours , minutes and seconds.
Example:
int totalseconds = 5049;
How do i use one message box to display the results in the form:
H:1 M:24 S:9
I'm trying to convert seconds to hours , minutes and seconds.
Example:
int totalseconds = 5049;
How do i use one message box to display the results in the form:
H:1 M:24 S:9
var timeSpan = TimeSpan.FromSeconds(5049);
int hr = timeSpan.Hours;
int mn = timeSpan.Minutes;
int sec = timeSpan.Seconds;
MessageBox.Show("H:" + hr + " M:" + mn + " S:" + sec);
Try this:
MessageBox message = new MessageBox();
int totalseconds = 5049;
int hours = totalSeconds / 3600;
int minutes = (totalSeconds % 3600) / 60;
int seconds = (totalSeconds % 3600) % 60;
message.ShowDialog(string.Format("{0}:{1}:{2}", hours, minutes, seconds));
I hope this helps
You can use a TimeSpan:
var ts = TimeSpan.FromSeconds(totalsecond);
MessageBox.Show(string.Format("H: {0} M:{1} S:{2}", ts.Hours, ts.Minutes, ts.Seconds));
Use TimeSpan
to convert from seconds,
var timeSpan = TimeSpan.FromSeconds(5049);
int hh = timeSpan.Hours;
int mm = timeSpan.Minutes;
int ss = timeSpan.Seconds;
MessageBox.Show("Hours" + hh + " Minutes" + mm + " Seconds" + ss);