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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:46:54+00:00 2026-05-31T10:46:54+00:00

I’m coding the following using VS2010, C#, ASP.NET: DateTime dt = DateTime.Parse(2012-03-11T02:53:58-08:00); //Date is

  • 0

I’m coding the following using VS2010, C#, ASP.NET:

DateTime dt = DateTime.Parse("2012-03-11T02:53:58-08:00"); //Date is taken from SQL database
string strDt = dt.ToString();   //Becomes: "3/11/2012 3:53:58 AM"

Is this April’s fools joke from Microsoft?

  • 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-05-31T10:46:55+00:00Added an answer on May 31, 2026 at 10:46 am

    The “incorrect” result (as darkmyst’s answer explains) is caused by the fact that March 11, 2012, 2:38:58 AM, was not a valid date and time in areas of the United States and Canada that observe daylight saving time. Evidently, your code is running on a computer in one of these areas.

    To convert a string to a DateTime, ignoring any time zone offset, you can call DateTimeOffset.Parse and then retrieve the DateTime component of the result:

    DateTime dt = DateTimeOffset.Parse("2012-03-11T02:53:58-08:00").DateTime;
    string strDt = dt.ToString();  // "3/11/2012 2:53:58 AM"
    

    UPDATE: So what’s the difference between DateTime.Parse and DateTimeOffset.Parse when the original string contains a time zone offset? Consider these two examples, which assume your current time zone is Pacific Time:

    // Example 1: DateTime.Parse(String)
    DateTime dt = DateTime.Parse("2012-03-11T06:00:00-04:00");
    Console.WriteLine(dt.ToString("o"));  // 2012-03-11T03:00:00.0000000-07:00
    

    DateTime.Parse uses the offset to adjust the parsed date and time to local time. Note that the time has changed from 6 AM to 3 AM, reflecting the conversion from Eastern Daylight Time (UTC-04:00) to Pacific Daylight Time (UTC-07:00). In your question, the time changed because DateTime.Parse automatically adjusted the time from Pacific Standard Time (UTC-08:00) to Pacific Daylight Time (UTC-07:00).

    // Example 2: DateTimeOffset.Parse(String)
    DateTimeOffset dto = DateTimeOffset.Parse("2012-03-11T06:00:00-04:00");
    Console.WriteLine(dto.DateTime.ToString("o"));  // 2012-03-11T06:00:00.0000000
    Console.WriteLine(dto.Offset);                  // -04:00:00
    

    DateTimeOffset.Parse is simpler. It just returns a DateTimeOffset value whose DateTime and Offset properties are set to the parsed date, time, and offset. But beware: If the time zone offset in the string doesn’t match the time zone you want to work with, then you need to adjust the resulting date and time yourself.

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

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
For some reason, after submitting a string like this Jack’s Spindle from a text
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.