ljs235 Posted August 23, 2003 Posted August 23, 2003 I am logging user actions throughout my program using datetime in the format hh:mm:ss:ff. I would like to calculate the difference between two times. Here is what I'm using for code: Dim Time As Date Time = DateTime.Now Dim TaskTime As TimeSpan = Time.Subtract(AddMainBTime) LogWriter.WriteLine("*TaskTime " & (TaskTime.ToString)) This works great, but I cannot figure out how to format the TaskTime to hh:mm:ss:ff. Right now, it writes to the file as hh:mm:ss.fffffff. When I try the following, I get the following error: 'Public Overrides Overloads Function ToString() As String' has no parameters and its return type cannot be indexed. LogWriter.WriteLine("*TaskTime " & (TaskTime.ToString("hh:mm:ss:ff"))) Any ideas on how I can format my TimeSpan value? Thanks. :) Quote
Jay1b Posted August 23, 2003 Posted August 23, 2003 You can break a string down using LEFT and RIGHT facilities, i cant remember the exact context for this, but i think this should give u an idea. MsgBox(Microsoft.VisualBasic.Left("hello", 3)) MsgBox(Microsoft.VisualBasic.Right("hello", 3)) SHOULD return the value "hel" and "llo", you can use this to break the dates down, and remove the annoying 20 out of 2003, or pretty much anything else - obviously you can also embed them into each other. Quote
Diablicolic Posted August 23, 2003 Posted August 23, 2003 Well if you take the 20 out, they might think 1903 :p Quote "Reality is fake, Dreams are for real"
ljs235 Posted August 23, 2003 Author Posted August 23, 2003 Thanks so much for your help. Here is how I resolved the situation: LogWriter.WriteLine("*TaskTime " & (Microsoft.VisualBasic.Left(TaskTime.ToString, 11))) Thank you!!! Quote
*Experts* Nerseus Posted August 23, 2003 *Experts* Posted August 23, 2003 You should stay away from Left and Right, in general. The string object supports a Substring method which does everything you need. Try this instead: LogWriter.WriteLine("*TaskTime " & TaskTime.ToString().Substring(11)) -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.