Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Saturday, April 24, 2010 9:59 PM
How can I set TimeSpan to 12 hour mode instead of its 0-23 mode?
All replies (7)
Saturday, April 24, 2010 10:25 PM ✅Answered
A TimeSpan represents a time interval (a difference between times), not a date or a time, so it makes little sense to define a 24 or 12 hour format to it...
Maybe you really want to use DateTime? In order to represent it in either format you use DateTime.ToString() with one of the formatters .
Cristian
Sunday, April 25, 2010 1:05 AM ✅Answered
Try to use the DateTime.ToString not the TimeSpan.ToString as Cristian said or as I posted in my previous response.
As Cristian said, timespan doesn't represent time of the day, it represents a duration (which can be 1 year for example), even though DateTime type has a TimeOfDay property which is of type TimeSpan.
Saturday, April 24, 2010 10:00 PM | 1 vote
Hey BloodRaven,
I think this can help you: >>
http://msdn.microsoft.com/en-us/library/aa332448%28VS.71%29.aspx
Regards
Saturday, April 24, 2010 10:14 PM | 1 vote
DateTime.Today.Add(timeSpan).ToString("hh:mm:ss tt")
Saturday, April 24, 2010 11:50 PM
Im sorry im not using .NET 4 framework..so i cant use tostring with parameters
Saturday, April 24, 2010 11:56 PM
It is available since .NET 1.0, it´s only the documentation link I provided which is for version 4.
Cristian.
Sunday, April 25, 2010 12:21 AM
I've tried putting the formatter in the ToString procedure...
but I get a "No overload for meathod for ToString takes 1 arguments"..
by the way my project is targeted to framework 3.5