Captastic Captastic - 3 months ago 14
C# Question

VB 2008 convert string "08:30:00" to datetime "08:30:00"

I'm working in Visual Studio 2008.

I have a string input in the format "hh:mm:ss" which I want to convert into a dateTime in the same format.

I have used the Convert.ToDateTime() function which converts it but adds a date to it as well. Is there a way to convert it without adding the date?

scanStartString = "08:00:00"
scanStart = Convert.ToDateTime(scanStartString)

'scanStart = "16/05/2011 08:00:00"
'required "08:00:00"


Cheers,
Cap

Answer

No. Try TimeSpan instead:

Dim time = TimeSpan.Parse("08:00:00")
Comments