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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T05:07:13+00:00 2026-05-23T05:07:13+00:00

I have the following NSDateFormatter: NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@MMM. d,

  • 0

I have the following NSDateFormatter:

NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"MMM. d, yyyy"];

NSLocale *usLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
[dateFormatter setLocale:usLocal];

and I have a while loop which starts at a given start date and increments the date by one until it reaches a specific end date.

NSDate *d = start;
while(YES){     
   NSString *td = [dateFormatter stringFromDate:d];
   NSLog(@"converted date %@ to %@",d,td);
   ...adds a date and re-initializes d
}

And I’m getting output such as the following:

2011-06-11 17:10:18.678 ListOf100[8784:707] converted date 2011-05-31 00:00:00 +0000 to May. 30, 2011
2011-06-11 17:10:18.687 ListOf100[8784:707] converted date 2011-06-01 00:00:00 +0000 to May. 31, 2011
2011-06-11 17:10:18.717 ListOf100[8784:707] converted date 2011-06-02 00:00:00 +0000 to Jun. 1, 2011

As you can see, all the dates are not converting properly. They are all off by 1 day. Why could this be happening? And how can I fix 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-05-23T05:07:14+00:00Added an answer on May 23, 2026 at 5:07 am

    Looks to me like the dates are being created in a different time zone than the one the formatter’s working in.

    NSDate * d = [NSDate dateWithTimeIntervalSince1970:800000];    
    // Arbitrary date
    
    NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"MMM. d, yyyy"];
    
    NSLocale *usLocal = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
    [dateFormatter setLocale:usLocal];
    
    
    //!!!: Set time zone
    [dateFormatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
    
    NSString *td = [dateFormatter stringFromDate:d];
    NSLog(@"converted date %@ to %@",d,td);
    

    Yields:

    2011-06-11 22:44:01.642 TimeZoneFormatter[21901:207] converted date 1970-01-10 06:13:20 +0000 to Jan. 10, 1970

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

Sidebar

Related Questions

I have the following: NSDateFormatter* df = [[NSDateFormatter alloc]init]; [df setDateFormat:@yyyy-MM-dd'T'HH:mm:ssZ]; NSDate* date =
I have the following code: NSDateFormatter * df = [[NSDateFormatter alloc] init]; [df setDateFormat:@yyyy-MM-dd
I have the following code: NSDateFormatter * df = [[NSDateFormatter alloc] init]; [df setDateFormat:@yyyy-MM-dd
I have the following code: NSDateFormatter * df = [[NSDateFormatter alloc] init]; [df setDateFormat:@yyyy-MM-dd
I have the following code: self.formatter = [[NSDateFormatter alloc] init]; [formatter setTimeZone:timeZone]; [formatter setDateFormat:@YYYY-MM-dd
I have the following code: NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; formatter.dateFormat = @yyyy-mm-dd;
I have this Following date Formatter code NSDateFormatter *df = [[NSDateFormatter alloc] init]; [df
I have this part of code: NSDate *date =nil; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]
I have following script: #!/usr/bin/python while True: x = raw_input() print x[::-1] I am
I am having problems with NSDateFormatter 's dateFromString method. I have the following date:

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.