Reputation: 373
i have a file which states duration for a particular event in format MMMMMMSS.Does any one know what kind of format is this for time duration and how to convert it into seconds.I'm using C# language
Upvotes: 0
Views: 254
Reputation: 172280
If the format is really M...MSS
(supplied as an integer value
), converting it to seconds is quite easy:
var seconds = (value / 100) * 60 + (value % 100);
Why does it work?
value / 100
removes the last two digits (integer division), thus returning MMMMMM
, andvalue % 100
returns the last two digits (modulo), i.e., SS
.MMMMMM * 60 + SS
, which should be pretty self-explanatory.Upvotes: 3
Reputation: 171431
My guess based on the format is that it could hold a maximum value of 99999959
, which would mean 999999
minutes and 59
seconds. But that is pure conjecture, and some sample data would help to bolster this idea. You may never know for certain though.
You should at least be able to determine whether the SS part ever exceeds 59 or not, which would be very important to know.
var input = "02345612";
int minutes = int.Parse(input.Substring(0, 6));
int seconds = int.Parse(input.Substring(6, 2));
int totalSeconds = minutes * 60 + seconds;
Upvotes: 0