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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:01:12+00:00 2026-05-11T09:01:12+00:00

I encountered what may be a leap year in .NET’s DateTime handling, specifically ToLocalTime()

  • 0

I encountered what may be a leap year in .NET’s DateTime handling, specifically ToLocalTime(). Here’s some code which reproduces the problem (I’m in the Pacific time zone):

DateTime dtStartLocal = DateTime.Parse('2009-02-28T23:00:00.0-08:00'); DateTime dtEndLocal = dtStartLocal.AddYears(3); DateTime dtStartUtc = dtStartLocal.ToUniversalTime(); DateTime dtEndUtc = dtStartUtc.AddYears(3); DateTime dtEndLocal2 = dtEndUtc.ToLocalTime(); DateTime dtStartLocal2 = dtStartUtc.ToLocalTime(); Console.WriteLine('START: 1={0}, 2={0}', dtStartLocal, dtStartLocal2); Console.WriteLine('END  : 1={0}, 2={1}', dtEndLocal, dtEndLocal2); Console.ReadLine(); 

The output is:

START: 1=2/28/2009 11:00:00 PM, 2=2/28/2009 11:00:00 PM
END : 1=2/28/2012 11:00:00 PM, 2=2/29/2012 11:00:00 PM

Notice the variable which I did ToUniversalTime().AddYears(3).ToLocalTime() is different than just AddYears(3), it’s one day ahead.

Has anyone encountered this? If this is expected, can someone explain the logic behind it?

NOTE: Yes, the best approach is to work entirely in UTC and not flip flop between them. This isn’t something which is effecting me, but a peculiarity I encountered. Essentially I misunderstood how AddYears() worked and now I can see why it’s doing what it’s doing (see my selected answer below).

  • 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. 2026-05-11T09:01:13+00:00Added an answer on May 11, 2026 at 9:01 am

    I think that this is working correctly.

    DateTime dtStartUtc = dtStartLocal.ToUniversalTime(); 

    PST is UTC-8. Therefore, this converts the time to March 1, 2009, 07:00:00.

    DateTime dtEndUtc = dtStartUtc.AddYears(3); 

    This adds three years to the previous time, putting it at March 1, 2012, 07:00:00.

    DateTime dtEndLocal2 = dtEndUtc.ToLocalTime(); 

    This converts the end time back to PST, which would be February 29, 2012, 11:00:00.

    I’d say this is just a side affect of converting between local and UTC time.

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

Sidebar

Ask A Question

Stats

  • Questions 79k
  • Answers 79k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer No, there's not really any way to control this as… May 11, 2026 at 4:13 pm
  • Editorial Team
    Editorial Team added an answer You're supposed to use combinations of gmtime/localtime and timegm/mktime. That… May 11, 2026 at 4:13 pm
  • Editorial Team
    Editorial Team added an answer Firstly, upgrade to SVN 1.6 on both client and server.… May 11, 2026 at 4:13 pm

Related Questions

I encountered what may be a leap year in .NET's DateTime handling, specifically ToLocalTime()
I encountered a problem when running some old code that was handed down to
So far, I've had great success using PyAMF to communicate between my Flex front-end
I've installed PostgreSQL using MacPorts on a couple of different computers, no problem, but
The setup: class Item { private int _value; public Item() { _value = 0;

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.