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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:42:54+00:00 2026-05-30T16:42:54+00:00

On the leap year, [NSDate date] returns 2012-03-01 HH:MM:SS +TTTT . On stackoverflow I’ve

  • 0

On the leap year, [NSDate date] returns 2012-03-01 HH:MM:SS +TTTT.

On stackoverflow I’ve often seen posts where today’s date is retrieved by simply calling [NSDate date]. The problem is that on the leap year this is not going to return the correct date. Now I understand that the leap year is actually a function of a calendrical system so it makes sense that NSDate wouldn’t recognize the leap year (or daylight savings time for that matter). However, this has the potential to wreck havoc in code – for example:

say you assign a file modification date by doing:

// assume today's date is 2012-02-29 10:00:00 +0000
NSDate *fileModificationDate = [NSDate date];    // 2012-03-01 10:00:00 +0000 is returned

Then at some point in the future you do a comparison to see when the file was last modified:

// assume it's the next day at 9 AM, ie 2012-03-01 09:00 +0000
NSTimeInterval timeSinceLastModification = [fileModificationDate timeIntervalSinceNow];

The returned timeSinceLasModification will be positive, signifying a time in the future which makes no sense!

My questions is: is it actually bad practice to use [NSDate date] to get the current date? Am I missing something important here?

Sorry for the long winded question…

  • 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-30T16:42:55+00:00Added an answer on May 30, 2026 at 4:42 pm

    I don’t know where you got the idea that NSDate doesn’t support leap day, but it’s absolutely wrong. I believe you’re getting confused because right now in GMT, the date string is 2012-03-01 03:42:07 +0000. This is correct. In GMT, it’s already March 1st. But if you ask for the date in the current locale (e.g. [[NSDate date] descriptionWithLocale:[NSLocale currentLocale]]) you’ll get a correct value of leap day. For me in PST, it’s

    Wednesday, February 29, 2012 7:42:46 PM Pacific Standard Time

    Note that NSDate itself is locale-unaware. The only change I made was asking it to return the string representation using the current locale instead of using GMT. I could take that same date object and ask for EST and it would give me the correct string for that time zone as well.

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

Sidebar

Related Questions

I need a regular expression to validate date (including leap year) in MMM dd
Can anyone explain the mathematical or simply the reasoning behind the leap year calculations
Instead of calculating the month and leap year to do this calculation. Is there
Possible Duplicate: how to find leap year? What will be the exact definition of
I encountered what may be a leap year in .NET's DateTime handling, specifically ToLocalTime()
How do I check if a year is a leap year? I have this
Is there an easy way to determine if a year is a leap year?
Consider a start date and an end date: NSDate *startDate, *endDate; For example, startDate
/* *Find if a year is leap or not */ public class LeapYear{ private
How can I check whether a year is bisect (i.e. a leap year) in

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.