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 9252875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T11:04:03+00:00 2026-06-18T11:04:03+00:00

I’m working on my first full C# project. I’m writing a portable class library

  • 0

I’m working on my first full C# project. I’m writing a portable class library for a Windows Store App / Windows Phone app and I’m actually having trouble with just DateTime.ParseExact and DateTime.TryParseExact.

The string I’m attempting to convert to a DateTime is in fact in Zulu. The example looks like these:

 2012-09-14T04:42:25.117Z
 2012-08-17T04:39:51.215Z

As you can see, we get down to milliseconds here. The following is the code being used:

DateTime _createdAt = DateTime.ParseExact(dateTime, TIMEFORMATTER,
                                CultureInfo.InvariantCulture,
                                DateTimeStyles.AssumeUniversal);

        return _createdAt;

And TIMEFORMATTER is a const declared up top:

const string TIMEFORMATTER = "yyyy-MM-ddTHH:mm:ss.fffZ"

I have been reading a number of SO posts looking for something that solves it. I figured that this one would just fine but it did not.

If anyone could point me in the right direction I would appreciate it. I have only worked with the Date object in VB.net.

Edit: Adding additional code from the library to show the full explanation

if (details.ContainsKey("created_at"))
{
    var time = details["created_at"].Stringify();
    Debug.WriteLine(time);
    DateTime _createdAt = FormatDateTime(time);

    Debug.WriteLine(_createdAt.ToLocalTime());
    Asana.Projects[indexOfProject].CreatedAt = _createdAt;
}



public static DateTime FormatDateTime(string dateTime)
{
    DateTime _createdAt = new DateTime();
    // 2012-09-14T04:42:25.117Z
    DateTime.TryParse(dateTime, out _createdAt);

    return _createdAt;
}

This is what goes to debug:

"2012-08-17T04:39:52.878Z"
1/1/0001 12:00:00 AM
"2012-08-17T05:17:12.530Z"
1/1/0001 12:00:00 AM
"2012-09-09T04:23:08.805Z"
1/1/0001 12:00:00 AM
"2012-08-17T04:39:51.215Z"
1/1/0001 12:00:00 AM
"2012-09-14T05:12:22.056Z"
1/1/0001 12:00:00 AM
"2012-08-06T04:51:10.662Z"
1/1/0001 12:00:00 AM
"2012-09-14T04:40:56.602Z"
1/1/0001 12:00:00 AM
"2012-08-17T04:52:33.264Z"
1/1/0001 12:00:00 AM
"2012-09-14T04:43:50.953Z"
1/1/0001 12:00:00 AM
"2012-09-13T06:07:16.530Z"
1/1/0001 12:00:00 AM
"2012-09-14T04:42:25.117Z"
1/1/0001 12:00:00 AM

Solution

With the help of Jeremy Thompson, I was actually able to debug my own mistake. Turns out this is my first time working with JSON data in .Net as well (used to Python).

.Stringify() and .GetString() do entirely different things when it comes to getting the text of the string. I opened a new console program and used Jeremy’s code to produce the same results he did. Worked flawlessly. When I went back to my library, I was getting format problems on some of the strings I was getting back. Then it hit me that in the debug window I was getting quotes around the JSON data.

The new working code is as follows:

// From the depths of a method
if (details.ContainsKey("created_at"))
{
    var time = details["created_at"].GetString();
    DateTime _createdAt = FormatDateTime(time);                
    Asana.Projects[indexOfProject].CreatedAt = _createdAt;
    Debug.WriteLine(Asana.Projects[indexOfProject].CreatedAt.ToLocalTime());
}

And the new FormatDateTime method (not that new as it turns out…):

public static DateTime FormatDateTime(string dateTime)
{
    DateTime _createdAt = new DateTime();
    DateTime.TryParseExact(dateTime, TIMEFORMATTER, CultureInfo.InvariantCulture,                                                                
                           DateTimeStyles.AssumeUniversal, out _createdAt);            
    return _createdAt;
}

Some example input/output:

2012-09-14T04:43:42.060Z
9/13/2012 10:43:42 PM
2012-09-09T04:23:08.805Z
9/8/2012 10:23:08 PM
2012-08-06T04:51:10.662Z
8/5/2012 10:51:10 PM

Thank you so much to those that were looking and thinking on it.

  • 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-18T11:04:04+00:00Added an answer on June 18, 2026 at 11:04 am
    string stringdate = "2012-09-14T04:42:25.117Z";
    DateTime date = new DateTime();
    DateTime.TryParse(stringdate,out date);
    MessageBox.Show(date.ToShortDateString());
    

    eg:

    MessageBox.Show(date.ToLocalTime().ToString());
    

    enter image description here

    Edit:

    In the MSDN DateTime.TryParseExact Method:

    The string parameter is parsed using default values. No white space
    other than that present in format is allowed. If string lacks a date
    component, the date of the returned DateTime value is set to 1/1/0001.

    I see you are suppplying the Date component. My only guess is that I’m in Australia and it works and we use DD-MM-YYYY and in the US its MM-DD-YYYY. Perhaps flip it around and see if that works, eg:

    “2012-17-08T04:39:52.878Z”

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

Sidebar

Related Questions

We're building an app, our first using Rails 3, and we're having to build
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am writing an app with both english and french support. The app requests
I am writing an app for my school newspaper, which is run completely online
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I am using Paperclip to handle profile photo uploads in my app. They upload
I'm making a simple page using Google Maps API 3. My first. One marker

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.