Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7744963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T09:53:39+00:00 2026-06-01T09:53:39+00:00

I want to parse a string that represent a DateTime in UTC format. My

  • 0

I want to parse a string that represent a DateTime in UTC format.

My string representation includes the Zulu time specification which should indicate that the string represent a UTC time.

var myDate = DateTime.Parse("2012-09-30T23:00:00.0000000Z");    

From the above I would expect myDate.Kind to be DateTimeKind.Utc, instead it is DatetimeKind.Local.

What am I doing wrong and how to Parse a string that represents a UTC time?

Many thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T09:53:41+00:00Added an answer on June 1, 2026 at 9:53 am

    I would use my Noda Time project personally. (Admittedly I’m biased as the author, but it would be cleaner…) But if you can’t do that…

    Either use DateTime.ParseExact specifying the exact format you expect, and include DateTimeStyles.AssumeUniversal and DateTimeStyles.AdjustToUniversal in the parse code:

    using System;
    using System.Globalization;
    
    class Test
    {
        static void Main()        
        {
            var date = DateTime.ParseExact("2012-09-30T23:00:00.0000000Z",
                                           "yyyy-MM-dd'T'HH:mm:ss.fffffff'Z'",
                                           CultureInfo.InvariantCulture,
                                           DateTimeStyles.AssumeUniversal |
                                           DateTimeStyles.AdjustToUniversal);
            Console.WriteLine(date);
            Console.WriteLine(date.Kind);
        }
    }
    

    (Quite why it would adjust to local by default without AdjustToUniversal is beyond me, but never mind…)

    EDIT: Just to expand on my objections to mattytommo’s suggestion, I aimed to prove that it would lose information. I’ve failed so far – but in a very peculiar way. Have a look at this – running in the Europe/London time zone, where the clocks go back on October 28th in 2012, at 2am local time (1am UTC):

    DateTime local1 = DateTime.Parse("2012-10-28T00:30:00.0000000Z");
    DateTime local2 = DateTime.Parse("2012-10-28T01:30:00.0000000Z");
    Console.WriteLine(local1 == local2); // True
    
    DateTime utc1 = TimeZoneInfo.ConvertTimeToUtc(local1);
    DateTime utc2 = TimeZoneInfo.ConvertTimeToUtc(local2);
    Console.WriteLine(utc1 == utc2); // False. Hmm.
    

    It looks like there’s a “with or without DST” flag being stored somewhere, but I’ll be blowed if I can work out where. The docs for TimeZoneInfo.ConvertTimeToUtc state

    If dateTime corresponds to an ambiguous time, this method assumes that it is the standard time of the source time zone.

    That doesn’t appear to be the case here when converting local2…

    EDIT: Okay, it gets even stranger – it depends which version of the framework you’re using. Consider this program:

    using System;
    using System.Globalization;
    
    class Test
    {
        static void Main()        
        {
            DateTime local1 = DateTime.Parse("2012-10-28T00:30:00.0000000Z");
            DateTime local2 = DateTime.Parse("2012-10-28T01:30:00.0000000Z");
    
            DateTime utc1 = TimeZoneInfo.ConvertTimeToUtc(local1);
            DateTime utc2 = TimeZoneInfo.ConvertTimeToUtc(local2);
            Console.WriteLine(utc1);
            Console.WriteLine(utc2);
    
            DateTime utc3 = local1.ToUniversalTime();
            DateTime utc4 = local2.ToUniversalTime();
            Console.WriteLine(utc3);
            Console.WriteLine(utc4);
        }
    }
    

    So this takes two different UTC values, parses them with DateTime.Parse, then converts them back to UTC in two different ways.

    Results under .NET 3.5:

    28/10/2012 01:30:00 // Look - we've lost information
    28/10/2012 01:30:00
    28/10/2012 00:30:00 // But ToUniversalTime() seems okay...
    28/10/2012 01:30:00
    

    Results under .NET 4.5 beta:

    28/10/2012 00:30:00 // It's okay!
    28/10/2012 01:30:00
    28/10/2012 00:30:00
    28/10/2012 01:30:00
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm want to parse a custom string format that is persisting an object graphs
I have a xsl parameter which a string. I want to parse that string,
I have a URL in string format that I want to parse to get
I want to be able to parse a string to an object that I
How can I parse a string that represents a date and/or time using iPhone
I want to parse a search string similar to that provided by Gmail using
I have a string that looks like this /root/test/test2/tesstset-werew-1 And I want to parse
I want to write a rename function to replace String names (which represent hierarchical
I want to be able to parse a Time from a string in Ruby
I have a string that I want to parse in Ruby: string = '{desc:{someKey:someValue,anotherKey:value},main_item:{stats:{a:8,b:12,c:10}}}'

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.