DateTime - parsing string with timezone in three letter acronyms

M

Michael Meckelein

Hello,

Wondering, if C# (framework 2.0) does not support parsing DateTime timezones
in three letter acronyms.

I would like to parse date strings like "2005 Nov 01 11:58:47.490 CST -6:00"
but it seems C# does not support the timezone letters (CST). I suppose to
use the symbol ZZZ for the timezone letters, but MSDE [1] pointed out that
it is not supported in C#, isn't it?

Of course I can write my own methode for parsing this (using regex or a list
of timezones, etc.) but I want to ask if there is no "build-in" support in
the 2.0 framework?

Best Regards,
Michael Meckelein

[1] DateTimeFormatInfo Class
http://msdn2.microsoft.com/en-us/library/system.globalization.datetimeformatinfo.aspx
 
C

Claes Bergefall

What exactly does that string mean? Is it -6 hours from UTC or -6 hours from
CST?
I'm guessing that you mean the time 11:58:47 CST, i.e. around noon somewhere
in the middle of the US? If so, the CST part is redundant since the timezone
offset (-6) is enough to know what time you're talking about.

Look into DateTime.TryParseExact/ParseExact if you want to control exactly
how the parsing should be done.


/claes
 
M

Michael Meckelein

Hello claes,

Thank you for your reply.
What exactly does that string mean? Is it -6 hours from UTC or -6 hours
from CST?
I'm guessing that you mean the time 11:58:47 CST, i.e. around noon
somewhere in the middle of the US? If so, the CST part is redundant since
the timezone offset (-6) is enough to know what time you're talking about.

You are absolutely right. It is -6 hours from UTC. I did not know for what
reason Cisco use this redundancy. In fact this is CISCO IOS compatible log
format e.g. used by VPN Concentrator.
Look into DateTime.TryParseExact/ParseExact if you want to control exactly
how the parsing should be done.

Actually this is what I did. But I am uncertain what string format to use
due to the missing timezone letters. Of course I can use string format "
yyyy MMM dd HH:mm:ss.fff CST z:00" for the given sample, however this does
not work in other timezones. As far as I see from the documentation there is
no placeholder for DateTime Format Strings such an ? or * as it is in regex.
So have I use regex in order to eliminate the timezone letters before I use
the DateTime.ParseExact? Or do you have any better solution at hand?

Thanks,
Michael
 
C

Claes Bergefall

Michael Meckelein said:
Hello claes,

Thank you for your reply.


You are absolutely right. It is -6 hours from UTC. I did not know for what
reason Cisco use this redundancy. In fact this is CISCO IOS compatible log
format e.g. used by VPN Concentrator.


Actually this is what I did. But I am uncertain what string format to use
due to the missing timezone letters. Of course I can use string format "
yyyy MMM dd HH:mm:ss.fff CST z:00" for the given sample, however this does
not work in other timezones. As far as I see from the documentation there
is no placeholder for DateTime Format Strings such an ? or * as it is in
regex. So have I use regex in order to eliminate the timezone letters
before I use the DateTime.ParseExact? Or do you have any better solution
at hand?

That's the only solution I can think of. Guess it wouldn't hurt to ask Cisco
if they have some solution to convert it to a real date object. And while
you're at it, ask them what the hell they were thinking when the decided
upon that format :)

/claes
 
M

Michael Meckelein

[eliminate the timezone letters]
That's the only solution I can think of. Guess it wouldn't hurt to ask
Cisco if they have some solution to convert it to a real date object.

I will try it, but it is not quite easy to get in touch with them.
And while you're at it, ask them what the hell they were thinking when the
decided upon that format :)

I will do so if I get a chance ;)

Thanks for your thoughts.

Michael
 
Top