|
|
|
start date: Wed, 15 Aug 2007 10:53:38 -0700,
posted on: microsoft.public.dotnet.framework
back
| Thread Index |
|
1
SpaceMarine
|
|
2
Peter Duniho
|
|
3
Peter Duniho
|
|
4
SpaceMarine
|
TimeSpace.Parse() usage
hello,
ive read the MSDN docs on using the TimeSpace.Pars() method to format
timespans, however i found their examples unclear.
currently i am doing this:
Dim startTime As DateTime = DateTime.Now
...
Dim endTime As DateTime = DateTime.Now
Dim elapsedTime As TimeSpan = endTime.Subtract(startTime)
writer.WriteLine("Time difference: {0} hours, {1} minutes, {2}
seconds.", elapsedTime.Hours, elapsedTime.Minutes,
elapsedTime.Seconds)
....but i get the impression there is a much simpler string formatter
technique. ive tried this, to no effect:
writer.WriteLine("Time difference: {0:hh:mm:ss}", elapsedTime)
anybody know the magic?
thanks!
sm
Date:Wed, 15 Aug 2007 10:53:38 -0700
Author:
|
Re: TimeSpace.Parse() usage
SpaceMarine wrote:
> [...]
> ....but i get the impression there is a much simpler string formatter
> technique. ive tried this, to no effect:
>
> writer.WriteLine("Time difference: {0:hh:mm:ss}", elapsedTime)
>
>
> anybody know the magic?
There's no magic. The TimeSpan class has no formatting options, so you
need to break it apart as in the example you found, if you are going to
use the TimeSpan directly.
One alternative is to convert the TimeSpan back to a DateTime, which of
course does have formatting options like you're trying to use:
writer.WriteLine("Time difference: {0:hh:mm:ss}",
new DateTime() + elapsedTime);
Sort of hacky, but it works.
Pete
Date:Wed, 15 Aug 2007 11:02:45 -0700
Author:
|
Re: TimeSpace.Parse() usage
On Aug 15, 1:02 pm, Peter Duniho wrote:
> SpaceMarine wrote:
> > [...]
> > ....but i get the impression there is a much simpler string formatter
> > technique. ive tried this, to no effect:
>
> > writer.WriteLine("Time difference: {0:hh:mm:ss}", elapsedTime)
>
> > anybody know the magic?
>
> There's no magic. The TimeSpan class has no formatting options
bummer. i had thought from all that jibjab on msdn's TimeSpan.Parse()
that there would be something like it.
http://msdn2.microsoft.com/en-us/library/system.timespan.parse(vs.71).aspx
thanks
sm
Date:Wed, 15 Aug 2007 12:20:34 -0700
Author:
|
Re: TimeSpace.Parse() usage
SpaceMarine wrote:
>> There's no magic. The TimeSpan class has no formatting options
>
> bummer. i had thought from all that jibjab on msdn's TimeSpan.Parse()
> that there would be something like it.
Yes. You'd think that you would be able to specify string formatting
for converting a TimeSpan to a string that's similar to the description
they offer for parsing from a string.
But as far as I know, they don't. And I have looked pretty thoroughly.
The TimeSpan.ToString() method doesn't even offer an overload with a
formatting string parameter.
Pete
Date:Wed, 15 Aug 2007 13:11:15 -0700
Author:
|
|
|