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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:24:44+00:00 2026-05-23T16:24:44+00:00

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]]; [dateFormatter setDateFormat:@yyyy-MM-dd]; NSDate *date1 =

  • 0
 NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
 [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
 [dateFormatter setDateFormat:@"yyyy-MM-dd"];
 NSDate *date1 = [dateFormatter dateFromString:@"1213-02-27"];
 NSTimeInterval nsdateResult = [date1 timeIntervalSince1970];
 NSTimeInterval sqliteResult = -23883638400;
 GHAssertEquals(sqliteResult, nsdateResult, @"sqlite and nsdate should agree");

The expected number is what SQLite tells me should be the result, but this test fails since Cocoa tells me -23883033600 instead of -23883638400…i.e. 4 days later!
What gives? Am I doing something wrong or is either SQLite or Cocoa wrong?

Edit

Just checked the math and it seems Cocoa is giving me a wrong value: according to Wolfram Alpha, there are 276431 days between 2/27/1213 and 1/1/1970. Take this times 24*60*60, and you get the value given by SQLite… so am I doing something wrong or is this some kind of Cocoa bug?

Edit 2
Fvu is right, it has to do with the Gregorian/Julian craziness back in 1582.

NSDate *date1 = [dateFormatter dateFromString:@"1582-10-15"];
NSDate *date2 = [dateFormatter dateFromString:@"1582-10-14"];
NSTimeInterval i = [date2 timeIntervalSinceDate:date1];

Surprisingly, i is 777600, i.e. 10/14 is 9 days LATER than 10/15 because it automatically is viewed as a Julian date whereas 10/15 is viewed as a Gregorian date. So basically what I will need to do is convert any dates before 10/15 from the Julian to the Gregorian calendar.

  • 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-23T16:24:44+00:00Added an answer on May 23, 2026 at 4:24 pm

    Your sample date predates the Gregorian calendar so I think some oddities can be expected. However, as at the introduction of the Gregorian calendar the date advanced by 10 days I don’t have a bulletproof explanation for the calculated 4 day difference.

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

Sidebar

Related Questions

I have this code NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@yyyy-mm-dd'T'HH:mm:ss.SSSSS]; NSDate *date
The following code: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setDateFormat:@MM/dd]; NSDate *newTime
NSString *dateStr = @2010-06-07 19:30:18; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@yyyy-MM-DD hh:mm:ss];
If I use the following code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@yyyy-MM-dd'T'HH:mm];
Here I got some ugly code: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@yyyy];
Hi Im trying to convert an NSString to NSDate NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]
Why does NSDateFormatter misinterpretes his own created dateString? NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
I'm initializing my NSDateFormatter thusly: NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease]; [dateFormatter setLocale:[[[NSLocale
The documentation is not clear about the date formatters NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc]
I tried to set NSDateFormatter for year, like this: NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]

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.