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 DateTimeFormatI nfo instance,
in which I'd replaced the DateTimeFormatI nfo.FullDateTim ePattern property
with my custom format string:
DateTimeFormatI nfo dtfi =
(DateTimeFormat Info)DateTimeFo rmatInfo.Invari antCulture.Clon e();
dtfi.FullDateTi mePattern = "dd/MMM/yyyy:HH:mm:ss zzz";
DateTime dt = DateTime.Parse( "23/Mar/2007:13:22:28 -0600", dtfi,
DateTimeStyles. AdjustToUnivers al);
For some reason, that doesn't work. If I try the exact same format string
with DateTime.ParseE xact(), 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 FullDateTimePat tern
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 DateTimeFormatI nfo instance,
in which I'd replaced the DateTimeFormatI nfo.FullDateTim ePattern property
with my custom format string:
DateTimeFormatI nfo dtfi =
(DateTimeFormat Info)DateTimeFo rmatInfo.Invari antCulture.Clon e();
dtfi.FullDateTi mePattern = "dd/MMM/yyyy:HH:mm:ss zzz";
DateTime dt = DateTime.Parse( "23/Mar/2007:13:22:28 -0600", dtfi,
DateTimeStyles. AdjustToUnivers al);
For some reason, that doesn't work. If I try the exact same format string
with DateTime.ParseE xact(), 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 FullDateTimePat tern
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
Comment