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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:20:33+00:00 2026-06-05T15:20:33+00:00

Simple case of trying to prove I can convert NSString to NSDate . Create

  • 0

Simple case of trying to prove I can convert NSString to NSDate. Create an NSDate, turn it into an NSString, then back into an NSDate. The date looks fine as a string, but when I convert it back I always get some date like 12/25/2011 …. Can someone spot my error?

 NSDateFormatter *df = [[NSDateFormatter alloc] init];
 [df setDateFormat:@"dd/MM/YY hh:mm a"];
 NSDate* b = [[NSDate alloc] init];
 NSString* f = [df stringFromDate:b]; // has the current date and time
 NSDate* dt =[df dateFromString:f];  // 12/25/2011 - where does it get this?
  • 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-05T15:20:34+00:00Added an answer on June 5, 2026 at 3:20 pm

    Try to use the following:

    [df setDateFormat:@"dd/MM/yyyy hh:mma"]; // or @"dd/MM/yy hh:mma"
    

    This is the result:

    Printing description of b:
    2012-06-12 13:06:16 +0000
    Printing description of dt:
    2012-06-12 13:06:00 +0000
    

    If you need more info I suggest to read date-formatter-examples.

    If you don’t use ARC make attention to memory leaks. For example, use [NSDate date] instead of [[NSDate alloc] init].

    Hope that helps.

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

Sidebar

Related Questions

This is for Play! Framework 2.0. I'm trying to write a simple test case
I have a pretty simple case which I started solving using foreach(), but then
A very simple use case for creating users in webapp2/appengine can be as follows:
I am trying to handle a simple case where i could be getting an
I am trying to write a simple CASE statement in MDX that returns Measure
This should be a very simple case, but I am pulling hair trying to
I'm trying a very simple case using a Python library called pyBrain and I
I am a beginner with Selenium, and I am trying a simple case of
Hey All! I am trying to use wonderxml (http://code.google.com/p/wonderxml/) to convert my xml into
I'm trying to convert the following (shortened for readability) to C# and running into

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.