Solved

How do I parse ZULU DateTime string

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

0
 

Author Comment

by:mohammad1000
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.
0
 
LVL 15

Accepted Solution

by:
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

0

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
Sent email using Shared Mailbox from outlook in C# 5 23
REXEX help Part 2 2 22
Expression Evaluater 3 24
Sort GridView by ID Descending 1 9
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

774 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