Good evening!
Given total number of minutes as input and you need to extract the total number of hours and remaining minutes out from the input, you need to use the TimeSpan class
specifically
FromMinutes() method. Based from the docs ,the FromMinutes method returns a TimeSpan object that represents a specified number of minutes, where the specification is accurate to the nearest millisecond.
C# Code
1
2
3
4 | TimeSpan span = TimeSpan.FromMinutes(1506);
var hours = (int) span.TotalHours;
var minutes = span.Minutes;
Console.WriteLine(hours + ":" + minutes.ToString("D2"));
|
VB.NET Code
1
2
3
4 | Dim span As TimeSpan = TimeSpan.FromMinutes(1506)
Dim hours = CInt(span.TotalHours)
Dim minutes = span.Minutes
Console.WriteLine(hours + ":" + minutes.ToString("D2"))
|
Output
Comments
Post a Comment