VB.Net &/OR ASP - Time * Number?

Alex S

New member
Basically,
I have a time e.g. 00:11:02 (this is the duration it takes for something to complete)
And I need to multiply it by a number e.g. 2
And I want the answer to be 00:22:04.

It should be simple enough...I think I need to change the format of the date,,,But can't remember how.
VB.net answer would be great and ASP would be a bonus thanks :)
 
Probably easiest to work with a TimeSpan object.
Dim ts as TimeSpan

I'm not sure what your time is stored in now. Is it already in a TimeSpan?
If not, you can convert from other formats:
string - ts = TimeSpan.Parse(string)
Numbers: ts = new TimeSpan(hours,minutes,seconds)
DateTime: ts = new TimeSpan(dt.Hour, dt.Minute, dt.Second)

You can't multiply a TimeSpan by a number directly, but you can create a new timespan using the constructor that takes a single Ticks parameter. You can multiply ticks to get the result you want:

ts = new TimeSpan(ts.Ticks*2)
 
Back
Top