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

  • SEARCH
  • Home
  • 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 8541219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T11:46:55+00:00 2026-06-11T11:46:55+00:00

I have a date serialized as a string 2012-06-20T13:19:59.1091122Z Using the DateTimeConverter , this

  • 0

I have a date serialized as a string “2012-06-20T13:19:59.1091122Z”

Using the DateTimeConverter, this gets converted to a DateTime object {22:49:59.1091122} with the Kind property set to “Local”.

eg. The following test fails:

    private static readonly DateTime UtcDate = new DateTime(634757951991091122, DateTimeKind.Utc);
    private const string UtcSerialisedDate = "2012-06-20T13:19:59.1091122Z";

    [Test]
    public void DateTimeConverter_Convert_From_Utc_String()
    {
        // Arrange
        var converter = TypeDescriptor.GetConverter(typeof(DateTime));

        // Act
        var result = converter.ConvertFrom(UtcSerialisedDate);

        // Assert
        Assert.AreEqual(UtcDate, result);
        Assert.AreEqual(DateTimeKind.Utc, ((DateTime)result).Kind);
    }

I’m a bit surprised by this… I would have expected that the DateTime object returned by the converter would be in UTC.

The docs do say that DateTimeConverter uses DateTime.Parse, but I’m guessing it must not use the DateTimeStyles.RoundtripKind option.

Is there any way around this?

  • 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-11T11:46:56+00:00Added an answer on June 11, 2026 at 11:46 am

    The real bug here is that DateTime.Parse() without any DateTimeStyles passed should still see the “Z” and recognize that it should be parsed as UTC. But good luck getting MS to acknowledge or fix that.

    The particular problem illustrated by your code sample is that the DateTimeConverter has to override methods from TypeConverter, and thus has no ability to pass extra parameters such as DateTimeStyles. It’s too bad it doesn’t implement some sort of static or threadstatic property for this. It does indeed take advantage of the thread’s Culture.CurrentCulture, but DateTimeStyles are a separate thing from culture, so alas – that’s another dead end.

    I assume you are locked in to using a converter, rather than just calling parse directly? Is this a hard requirement? If not, you could do the following:

    public static object ConvertFrom<T>(string value)
    {
      if (typeof(T) == typeof(DateTime))
        return DateTime.Parse(value, null, DateTimeStyles.RoundtripKind);
    
      var converter = TypeDescriptor.GetConverter(typeof(T));
      return converter.ConvertFrom(value);
    }
    

    Another approach would be to use a DateTimeOffsetConverter instead – it understands the Z timezone properly. You could then use the .UtcDateTime property of the result to get back to a DateTime with a UTC kind.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have date 2012-04-02 10:01:00 am I want to show this date in with
I have a date in String format, mm/dd/yyyy I want to convert this to
I have a serialized json string in the format: [{\Version\:\8.63\,\Date\:\07\/11\/2011 00:00:00\,\Count\:213}, {\Version\:\1.0\,\Date\:\07\/11\/2011 00:00:00\,\Count\:1}, .........
I have date formatted in this way: 2010-02-04T00:00:00 I use this code to parse
I have date in sting object in following format. dd/mm/yyyy I want to change
I have some date and I want to get last x day before this
I have this block of code that eventually get serialized to JSON, for use
I have an Action Method that returns a JSON-serialized object. The problem I'm having
I'm using SQLite.cs wrapper for helping me with the database and I have this
Is there any way I can define how a DateTime should be serialized/deserialized using

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.