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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:52:49+00:00 2026-06-08T19:52:49+00:00

This question was asked a lot, but I can’t find the solution for my

  • 0

This question was asked a lot, but I can’t find the solution for my problem.

What I want:
Convert a date given as a NSString into a NSDate with a complete different format.
I want to convert Tue, 31 Jul 2012 10:15:00 GMT to 2012-07-31 10:15:00 +0000.

My code:

NSString *startDateString = @"Tue, 31 Jul 2012 10:15:00 GMT"; //in real from a server

NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
[formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss"];

NSDate *startDate = [formatter dateFromString:startDateString];
[formatter setDateFormat:@"yyy-MM-dd HH:mm:ss'Z'"];

NSString *endDateString = [formatter stringFromDate:startDate];
NSDate *endDate = [formatter dateFromString:endDateString];

Problem:
endDate is nil.

Edit:
Found a strange behaviour.
When I change the first dateFormat to @"EEE, dd MMM yyy HH:mm:ss 'GMT'" (added GMT) then the output of endDate is correct, but only in the Simulator. On the device it is still nil.
With the dateFormat without “GMT” the value is nil on the Simulator and on the Device.

  • 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-06-08T19:52:51+00:00Added an answer on June 8, 2026 at 7:52 pm

    this is working well for me, you might use it:

    NSString *startDateString = @"Tue, 31 Jul 2012 10:15:00 GMT"; //in real from a server
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];
    [formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ssZZZ"]; // SPOT the difference in this line
    
    NSDate *startDate = [formatter dateFromString:startDateString];
    [formatter setDateFormat:@"yyy-MM-dd HH:mm:ssZZZ"]; // and SPOT the difference in this line
    
    NSString *endDateString = [formatter stringFromDate:startDate];
    NSDate *endDate = [formatter dateFromString:endDateString];
    
    NSLog(@"%@", endDate);
    

    the endDate is:

    2012-07-31 10:15:00 +0000
    

    UPDATE #1

    it has been tested on the real device only!

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

Sidebar

Related Questions

Seen this question asked a lot but can't seem to find an answer. So
This question seems to get asked a lot, but I can't find an answer
I'm sure this question is asked a lot but I cannot find an answer
This question has been asked a lot here, but i still can't fix my
Maybe this question has been asked a lot, but I still can't understand how
Yes, I know this question has been asked a lot of times, but I
This question seems to have been asked a lot, but I haven't seen an
This question has been asked a lot but everywhere the answers fall short. I
This question has been asked a lot of times in many forums. But I
I fully understand this question has been asked a lot , but I'm asking

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.