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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:02:55+00:00 2026-06-06T13:02:55+00:00

I just simply can’t figure out how to set NSDateFormatter date format so [formatter

  • 0

I just simply can’t figure out how to set NSDateFormatter date format so [formatter dateWithString:] does not return a nil.

The date looks as follows :

2008-08-18T14:32:22.1875000+01:00

I tried

formatter setDateFormat:@"yyyy-MM-ddTHH:mm:ss.fffffffzz+GMT"];

Doesn’t seem to work :(. Any suggestions, please help.

Ok thanks for answering, it seems like I mislead people with my question a little so I try to rephrase it, sorry for that, maybe its just bit late for programming. I need a date wrapper object so I don’t have to parse the string containing the date myself. Basically I get a string from a Database I need to parse to I can use it in my UI.

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];    
formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZZZZ";
formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
NSDate *date = [formatter dateFromString:@"2008-08-18T14:32:22.1875000+01:00"];
NSLog(@"%@", date);

That prints nil

What I want is NSString->NSDat, so I can ask it maybe what month it contains, or what time it contains. I see now that NSDate does not have such method. That was a foolish thing to assume. Any Ideas,now?

  • 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-06T13:02:56+00:00Added an answer on June 6, 2026 at 1:02 pm

    Per the unicode documentation there’s no f. Assuming you want subseconds, that should be S. You also need to put the T in quotes if you want it to transfer literally. I think you’re confused about z too, and probably want ZZZZ rather than zz+GMT. So:

    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZZZZ";
    NSLog(@"%@", [formatter stringFromDate:[NSDate date]]);
    

    Per the QA1480, you may also want explicitly to set a locale of en_US_POSIX, if you want to produce a technical string for storage. It reserves the right to adjust your requested fields otherwise per the current locale, assuming you want to display the string. So that’d be:

    NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
    formatter.locale = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease];
    formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZZZZ";
    NSLog(@"%@", [formatter stringFromDate:[NSDate date]]);
    

    As per ctrahey’s answer, that doesn’t quite get the format you want, ending up at e.g.

    012-06-22T16:44:32.9310000GMT-07:00
    

    i.e. the letters ‘GMT’ have crept in there. Switching to a single Z gets rid of the explicit reference to GMT but also removes the colon.

    Edit: per your example code:

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];    
    formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss.SSSSSSSZZZZ";
    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    NSDate *date = [formatter dateFromString:@"2008-08-18T14:32:22.1875000+01:00"];
    NSLog(@"%@", date);
    

    That fails because your input string doesn’t match the supplied date format — it’s missing the letters GMT before the +01:00. Since there doesn’t seem to be a unicode date string that exactly matches what you have in your database, probably the easiest thing is just to remove the colons. E.g.

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];    
    formatter.dateFormat = @"yyyy-MM-dd'T'HHmmss.SSSSSSSZ";
    formatter.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"];
    NSString *sourceString = @"2008-08-18T14:32:22.1875000+01:00";
    NSDate *date = [formatter dateFromString:[sourceString stringByReplacingOccurrencesOfString:@":" withString:@""]];
    NSLog(@"%@", date);
    

    For me that outputs 2008-08-18 13:32:22 +0000.

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

Sidebar

Related Questions

I can not figure out what is happening here but somehow my page is
I have a program I made in C++ that does not use classes, just
I played around with it for a while, but I simply can't figure it
Just a simple question, but can't get an answer on my own. In memory
how can I write just a simple disassembler for linux from scratches? Are there
On my website users can keyword search and find desired results. (Just a simple
Is there a fast, low-garbage way to do it? I can't just do simple
I just can't get the ajax service to work. A simple class to $.get(http://google.com)
Simple question. Just wondering if this can be done without me having to enforce
This is a super simple question that I just can't seem to find a

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.