Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VB.NET DateTime from seconds only

I would like to get a time (for example 03:00:03) feeding only the seconds, but nothing else.

Using the Microsoft.VisualBasic runtime, I could say

 Dim sTimeRemaining As String = DateAndTime.TimeSerial(0, 0, iSecondsRemaining)

I would use this to show the user how long a download is still going to take.

Can somebody tell me how to do this without the Microsoft.VisualBasic runtime?

Thank you!

like image 226
tmighty Avatar asked May 25 '26 18:05

tmighty


1 Answers

You could use

Dim sTimeRemaining As Date = New Date().AddSeconds(iSecondsRemaining)

Note that you should set Option Strict to On. Then your code wouldn't compile since DateAndTime.TimeSerial returns a Date and not a String. But it's a good thing because you are forced to build more robust and type safe code.

Perhaps it would also be better to use a TimeSpan instead of a Date in this case.

Dim seconds = TimeSpan.FromSeconds(iSecondsRemaining)
like image 188
Tim Schmelter Avatar answered May 28 '26 09:05

Tim Schmelter



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!