Donate

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
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
Get Total Hours And Minutes From Total Minutes Using TimeSpan Class In C# And VB.NET

Comments

Donate

Popular Posts From This Blog

WPF CRUD Application Using DataGrid, MVVM Pattern, Entity Framework, And C#.NET

How To Insert Or Add Emojis In Microsoft Teams Status Message

Bootstrap Modal In ASP.NET MVC With CRUD Operations