How do I parse ZULU DateTime string

Posted on 2009-07-11
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.

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

Question by:mohammad1000
LVL 15

Expert Comment

ID: 24832254
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


Author Comment

ID: 24832414
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.
LVL 15

Accepted Solution

jinal earned 20 total points
ID: 24832827
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


Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Two different visual studio versions 3 23
C# Json POSt to Rest API 4 38
Error in script 11 48
How to join on ID, with prefix? 15 17
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

863 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

19 Experts available now in Live!

Get 1:1 Help Now