Get Total Hours And Minutes From Total Minutes Using TimeSpan Class In C# And VB.NET
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
VB.NET Code
Output
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")) |
Comments
Post a Comment