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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T10:22:20+00:00 2026-05-24T10:22:20+00:00

My date string that I am getting is 8/5/2011 1:38:13 PM of this format.

  • 0

My date string that I am getting is 8/5/2011 1:38:13 PM of this format. How do I convert it to NSDate?

I tried:

[dateFormatter setDateFormat:@"mm/dd/yyyy 'T' hh:mm:ss a"];
NSString *currentDate = [dateFormatter stringFromDate:currentDateString];

It returns nil. Any thoughts?

  • 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-24T10:22:21+00:00Added an answer on May 24, 2026 at 10:22 am

    The reason it returns nil is because you are calling the wrong method, there is no T in your date string (characters inside of single quotes ' in are literals), and the PM is not “P.M.”. Things that are not breaking it but are not completely correct is you are trying to parse the month as a minute and your date string can have a minimum of 1 digit month, day, and hour so you should not use 2 specifiers which would pad them if you were to create a string from the date. Try this:

    NSString *currentDateString = @"8/5/2011 1:38:13 PM";
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //Set the AM and PM symbols
    [dateFormatter setAMSymbol:@"AM"];
    [dateFormatter setPMSymbol:@"PM"];
    //Specify only 1 M for month, 1 d for day and 1 h for hour
    [dateFormatter setDateFormat:@"M/d/yyyy h:mm:ss a"]; 
    NSDate *currentDate = [dateFormatter dateFromString:currentDateString];
    
    NSLog(@"current date: %@", currentDate);
    //Example of the format using the actual date
    NSLog(@"%@", [dateFormatter stringFromDate:[NSDate date]]);
    [dateFormatter release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been passed a date string that looks like this: Thu%20Mar%2011%202010%2015%3A09%3A11%20GMT%2B0000%20(BST) I want
I got a string that contains the current date by using this : NSString
I'm trying to figure out a way to format a date string that sits
A search API is returning date in String format,I want to compare that date
I have the following date: 2011-08-12T20:17:46.384Z . What format is this? I'm trying to
I have a date in string like NSString Date = Dec 21 2011; I
I have a date string of the form '2009/05/13 19:19:30 -0400'. It seems that
date here my problem: String datetime = 2012-03-24 23:20:51; I know that that string
I have a service that give me a date time string in the following
I have a jArray and a string from that jArray, message2: [{date:2012,count:1,message : message1},

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.