I would like to convert a double in to a datetime.
This is not a conversion from Excel. I have a double representing seconds and would simply like it represented as time in minutes and seconds.
121.0005 = 2:01 mins
I would like to convert a double in to a datetime.
This is not a conversion from Excel. I have a double representing seconds and would simply like it represented as time in minutes and seconds.
121.0005 = 2:01 mins
Use TimeSpan
:
double seconds = 121.0005;
TimeSpan sp = TimeSpan.FromSeconds(seconds);
Console.Write(string.Format("{0} mins", sp.ToString(@"m\:ss")));
Instead of DateTime
what you need is TimeSpan
, since your input is representing a time value, not Date
.
Use TimeSpan.FromSeconds
method.
double sec = 121.0005;
TimeSpan ts = TimeSpan.FromSeconds(sec);