How to convert double to dateTime value in C #?

I would like to convert double to datetime.

This is not a conversion from Excel. I have a double view of seconds and just want to represent it as time in minutes and seconds.

121.0005 = 2:01 min

+4
source share
2 answers

Use TimeSpan:

double seconds = 121.0005;
TimeSpan sp = TimeSpan.FromSeconds(seconds);
Console.Write(string.Format("{0} mins", sp.ToString(@"m\:ss")));
+10
source

Instead DateTimeyou need to TimeSpan, since your input represents a time value, not Date.

Use the method TimeSpan.FromSeconds.

double sec = 121.0005;
TimeSpan ts = TimeSpan.FromSeconds(sec);
+7
source

Source: https://habr.com/ru/post/1527552/


All Articles