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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:15:15+00:00 2026-06-18T04:15:15+00:00

I have an NSDateformatter that is not working correctly. I got my date as

  • 0

I have an NSDateformatter that is not working correctly. I got my date as a string like this.

2013-02-20 00:00:00

And I need to return it as an NSDate like this

2013-02-20

What I’ve got at the moment is this.

 NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
 [dateFormat setDateFormat:@"yyyy-MM-dd hh:mm:ss"];

[dateFormat setDateFormat:@"yyyy-MM-dd"];
[dateFormat dateFromString:dateString]

But this is not working.
Any help ?

  • 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-18T04:15:17+00:00Added an answer on June 18, 2026 at 4:15 am

    if you have more than on date to parse, it could be worthy to create one input and one output date formatter

    static NSDateFormatter *inputDateFormatter;
    static NSDateFormatter *outputDateFormatter;
    if (!inputDateFormatter) {
        inputDateFormatter= [[NSDateFormatter alloc] init];
        [inputDateFormatter setDateFormat:@"yyyy-MM-dd hh:mm:ss"];
    
        outputDateFormatter = [[NSDateFormatter alloc] init];
        [outputDateFormatter setDateFormat:@"yyyy-MM-dd"];
    }
    NSDate *date = [inputDateFormatter dateFromString:@"2013-02-20 00:00:00"];
    
    NSString *string = [outputDateFormatter stringFromDate:date];
    
    NSLog(@"%@", string);
    

    result

    2013-02-20
    

    as NSDateFormatter are expensive to create, you should either store them in a singleton or declare them static to create them once for that method.


    And I need to return it as an NSDate like this

    A date has no format, it is just a point in time. you will have to creta a string with the desired format where needed.

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

Sidebar

Related Questions

I have a string like that: NSString *string = @2012-06-14T00:00:00+03:00; I tried this and
I have a string that contain date: 2012-05-25 and i wan to convert this
I'm creating a date like this : NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; NSDateFormatter
I have a NSString that I want to load into a NSDate. The string
i need to convert some date that i have in NSString to NSString in
I have problem using the NSDateFormatter to parse a date string. I have implemented
I have a string that has a date format of HH:mm so for example
I have some code I use to sort calendar dates that looks like this:
Possible Duplicate: NSDateFormatter and yyyy-MM-dd I have an NSDate variable in format yyyy-MM-dd that
i have a function to convert into NSDate by using NSDateFormatter . +(NSDate*)getDateFromCurrentTimestamp:(NSString*)currentTimestamp{ //

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.