P
Peter Duniho
I'm sure there's a good explanation for this, but I can't figure it out.
I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance,
in which I'd replaced the DateTimeFormatInfo.FullDateTimePattern property
with my custom format string:
DateTimeFormatInfo dtfi =
(DateTimeFormatInfo)DateTimeFormatInfo.InvariantCulture.Clone();
dtfi.FullDateTimePattern = "dd/MMM/yyyy:HH:mm:ss zzz";
DateTime dt = DateTime.Parse("23/Mar/2007:13:22:28 -0600", dtfi,
DateTimeStyles.AdjustToUniversal);
For some reason, that doesn't work. If I try the exact same format string
with DateTime.ParseExact(), it works fine.
My expectation was that the Parse() method would try all of the various
format strings it knows about, which would include the FullDateTimePattern
string I set. But apparently it doesn't do that.
Can anyone tell me what it _does_ do, and why it doesn't at least include
all of the patterns set within the format pattern properties given to it?
In my case, using ParseExact() is a reasonable work-around, but I'm
wondering if there's a way to do this using the Parse() method. It sure
seems like it ought to work.
Thanks,
Pete
I tried using DateTime.Parse() with a custom DateTimeFormatInfo instance,
in which I'd replaced the DateTimeFormatInfo.FullDateTimePattern property
with my custom format string:
DateTimeFormatInfo dtfi =
(DateTimeFormatInfo)DateTimeFormatInfo.InvariantCulture.Clone();
dtfi.FullDateTimePattern = "dd/MMM/yyyy:HH:mm:ss zzz";
DateTime dt = DateTime.Parse("23/Mar/2007:13:22:28 -0600", dtfi,
DateTimeStyles.AdjustToUniversal);
For some reason, that doesn't work. If I try the exact same format string
with DateTime.ParseExact(), it works fine.
My expectation was that the Parse() method would try all of the various
format strings it knows about, which would include the FullDateTimePattern
string I set. But apparently it doesn't do that.
Can anyone tell me what it _does_ do, and why it doesn't at least include
all of the patterns set within the format pattern properties given to it?
In my case, using ParseExact() is a reasonable work-around, but I'm
wondering if there's a way to do this using the Parse() method. It sure
seems like it ought to work.
Thanks,
Pete