Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1002
  • Last Modified:

How do I parse ZULU DateTime string

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
mohammad1000
Asked:
mohammad1000
1 Solution
 
oobaylyCommented:
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
 
mohammad1000Author Commented:
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
 
jinalCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now