DataTime - TryParseExact

B

Brian R.

We are working with a system (black box to us) that provides date/time in the
following string format:

"Tues Sep 30 15:16:41 PDT 2008"

Where PDT is the local time zone.

We need to parse this into a DateTime object to be used for comparisons and
the problem is that we can't figure out how to get the time zone to parse.
We tried 'zzz' for that part of the format string, but it seems to be
expecting +/- hours and not a string PDT.

How can I parse this without having to create a switch statement for every
possible time zone?

Getting them to write out GMT (UTC) time is not an option as it is a black
box.

Thanks,
 
Z

Zhi-Xin Ye [MSFT]

Dear Brian,

As far as I konw, the DateTime parsing process does not support time zone
abbreviations like PDT, EST, etc.

If you are always in the time zone indicated by the time zone abbreviation
in the datetime string, you can remove the time zone abbreviation from the
string before parsing it, and treat the result as a local datetime.

If you are not always in the time zone indicated by the time zone
abbreviation, you have to handle the time zone abbreviation part by
yourself. For example, you can replace the "PDT" with "-0700", and so on.

Sincerely,
Zhi-Xin Ye
Microsoft Managed Newsgroup Support Team

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
(e-mail address removed).

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subscriptions/aa948868.aspx#notifications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://support.microsoft.com/select/default.aspx?target=assistance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
J

Jon Skeet [C# MVP]

We are working with a system (black box to us) that provides date/time inthe
following string format:

"Tues Sep 30 15:16:41 PDT 2008"

Where PDT is the local time zone.  

We need to parse this into a DateTime object to be used for comparisons and
the problem is that we can't figure out how to get the time zone to parse..  
We tried 'zzz' for that part of the format string, but it seems to be
expecting +/- hours and not a string PDT.

How can I parse this without having to create a switch statement for every
possible time zone?  

If you're using .NET 3.5, I suggest you look at the TimeZoneInfo
class. Then you can take the original string, try to find the timezone
part of it (if it's in a nice standard format, that will help a lot!)
and find the TimeZoneInfo for it. Remove the timezone part from the
string, then parse the rest. Then you've got a DateTime (or
DateTimeOffset) and a TimeZoneInfo - between the two of them, you can
work out whatever you need to.

Jon
 
B

Brian R.

Thanks for the information. I will try looking into 3.5 and see if I can
make use of that data.

Thanks,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top