473,327 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

DataTime - TryParseExact

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,
--
Brian R.

Oct 1 '08 #1
3 3199
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:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/en-us/subs...#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/...tance&ln=en-us.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 2 '08 #2
On Oct 1, 11:06*pm, Brian R. <8B2H4R_N9G5M...@noemail.nospamwrote:
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
Oct 2 '08 #3
Thanks for the information. I will try looking into 3.5 and see if I can
make use of that data.

Thanks,

--
Brian R.

"Jon Skeet [C# MVP]" wrote:
On Oct 1, 11:06 pm, Brian R. <8B2H4R_N9G5M...@noemail.nospamwrote:
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?

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
Oct 2 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Sun | last post by:
Hi all, I am inserting datatime value into mysql table, while select value its giving 0000-00-00 00:00:00 value. mysql> insert into dtest values('02-17-05 17:08:02'); Query OK, 1 row...
8
by: Zibi | last post by:
I have some problem with datatime. SELECT * FROM stat WHERE data > '2005-05-24 14:07:28' ORDER BY id Asc I got the error: Microsoft OLE DB Provider for SQL Server error '80040e07' The...
14
by: expertware | last post by:
Ok! to avoid confusion I will start a new argument. Thanks!! FIREFOX 1.0.7 AND IE6 viewed through DATATIME: a summary REPORT ===============================================================...
5
by: Ali Baba | last post by:
Hi, Is there is equivalent of VB's DateDiff() method in C#. I need to find difference in months between two dates that are years apart. Docs says that I can use TimeSpan like: TimeSpam ts =...
3
by: Quentin Huo | last post by:
Hi: I have a string which value has the date format, like "Wed, 15 Sep 2004 15:52:36 GMT", and I want to create an object of DateTime, like: DateTime dt = (DateTime)(theDateString);
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.