What would be the equivalent in VB.NET of the time format [h]:mm in EXCEL ?

Hi Experts

In EXCEL, we have a very practical time format [h]:mm that preserve the hours in hours. For example, 25 hours in [h]:mm would be expressed as 25:00 instead of 01:00 for all other formats with hh, like hh:mm or HH:mm.

What would be the equivalent in VB.NET of this very neat format? Is there a simple way to format 25 hours in VB.NET like 25:00 ? Do I have to build a formatting method of my own?

Thank you for the information.

mojoansoolAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jorge PaulinoConnect With a Mentor IT Pro/DeveloperCommented:
I don't think you have ... but you can build your own
Dim time As New TimeSpan(10, 5, 0) ' 10:05:00
Dim newTime As TimeSpan = time.Add(New TimeSpan(25, 0, 0)) ' Add 25 hours

Debug.WriteLine(String.Format("{0}:{1}", newTime.TotalHours.ToString("00"), _
                                              newTime.Minutes.ToString("00")))

Open in new window

0
 
Alexandre SimõesManager / Technology SpecialistCommented:
How do you get that value?

If you use a TimeSpan you can simply get the Hours and the minutes.


Dim ts As New TimeSpan(25, 22, 0)
Dim time As String = (ts.Hours.ToString() & ":") + ts.Minutes.ToString()
0
 
mojoansoolAuthor Commented:
For this format I'm looking for, I guess I will have to settle for a custom build.  In the mean time, jpaulino made me realize the existence of the TimeSpan structure. Thanks.
0
All Courses

From novice to tech pro — start learning today.