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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:35:50+00:00 2026-05-26T05:35:50+00:00

i have a problem to convert a NSString to a NSDate and back to

  • 0

i have a problem to convert a NSString to a NSDate and back to a formatted NSString. The codesnippet works without any problem on the iOS Simulator but doesnt work on my iPhone 4.

NSString *pubDate = @"Tue, 18 Oct 2011 05:00:00 +0100";

NSDateFormatter *formater1 = [[NSDateFormatter alloc] init];
[formater1 setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss ZZZ"];

NSDate *d = [formater1 dateFromString:pubDate];
NSLog(@"d: %@", d);


NSDateFormatter *formater2 = [[NSDateFormatter alloc] init];
[formater2 setDateFormat:@"dd MMM yyyy"];

NSString *k = [formater2 stringFromDate:d]; 
NSLog(@"k: %@", k);

[formater1 release];
[formater2 release];

The output from the simulator is:

d: 2011-10-18 04:00:00 +0000
k: 18 Oct 2011

The output on the device is:

d: (null)
k: (null)

Any suggestions?

  • 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-26T05:35:51+00:00Added an answer on May 26, 2026 at 5:35 am

    You need to set a locale on the date formatters.

    NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    
    //...
    formater1.locale = locale;
    
    //...
    formater2.locale = locale;
    
    //...
    [locale release];
    

    If you don’t set the locale then user’s settings can change the provided string to conform with user’s setting, such as change 12h to 24h clock or vice versa.

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

Sidebar

Related Questions

I have a problem with my app, which run well on the simulator but
I have a really weird problem. Basically just convert a char to nsstring and
have small problem, and would very much appreciate help :) I should convert byte
Hey, I am trying to convert NSString to a C string using cStringUsingEncoding but
How can I convert a NSString containing a number of any primitive data type
I have some problem convert C++ code to PHP. The purpose is I need
I have a problem when I convert an object to XML. The result is
i have mathematical problem which I'm unable to convert to PHP or explain differently.
I have this weird problem that a convert of a string on my machine
I have a problem I need to convert char [] to String, hexadecimal format

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.