Solved

How do I parse ZULU DateTime string

Posted on 2009-07-11
3
978 Views
Last Modified: 2012-05-07
I need to be able to correctly parse a string to a DateTime type using the DateTime.ParseExact.
Any suggestion would be appreciated.
Thanks

CultureInfo provider = CultureInfo.InvariantCulture;

            string dateString = "091128Z July 2009";

            string format = "ddHHmmZ MMM yyyy";

            DateTime result;
 

            result = DateTime.ParseExact( dateString, format, provider );
 

The result should be   09/07/2009   11:28 AM

Open in new window

0
Comment
Question by:mohammad1000
3 Comments
 
LVL 15

Expert Comment

by:oobayly
Comment Utility
You've specified the format string to parse the month as an abbreviated string. Try this:
string format = "ddHHmmZ MMMM yyyy";

Open in new window

0
 

Author Comment

by:mohammad1000
Comment Utility
Changing the format type gives incorrect time.
091128Z July 2009 converts to 7/9/2009 4:28:00 AM.

The result should be 7/9/2009  11:28 AM.
0
 
LVL 15

Accepted Solution

by:
jinal earned 20 total points
Comment Utility
You have to call ToUniversalTime at last.
            DateTime dt = result.ToUniversalTime();


CultureInfo provider = CultureInfo.InvariantCulture;

            string dateString = "091128Z July 2009";

            string format = "ddHHmmZ MMMM yyyy"; 

            DateTime result;
 

            result = DateTime.ParseExact(dateString, format,provider);

            DateTime dt = result.ToUniversalTime();

Open in new window

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now