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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:09:46+00:00 2026-05-27T09:09:46+00:00

I have a string and need convert it to a date, but it doesn’t

  • 0

I have a string and need convert it to a date, but it doesn’t convert correctly. I don’t know why… my code is:

NSString * fecha = @"2011-12-07 11:11:29.657";

NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.ZZZ"];

NSDate *dateFromString = [[NSDate alloc] init]; 
dateFromString = [dateFormatter dateFromString:fecha]; 

NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
unsigned units = NSYearCalendarUnit | NSMonthCalendarUnit |  NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit;

NSDateComponents *components = [calendar components:units              
                                           fromDate:dateFromString];
 NSInteger* hour = [components hour];
 NSInteger* minute = [components minute];
 NSInteger* second = [components second];  

NSLog(@"Fecha: %@",fecha);
NSLog(@"Format: %@",dateFormatter.dateFormat);
NSLog(@"date: %@",dateFromString);

In my log:

2011-12-07 11:36:11.750 Catalogo-V1[13741:207] Fecha: 2011-12-07 11:11:29.657
2011-12-07 11:36:11.750 Catalogo-V1[13741:207] Format: yyyy-MM-dd HH:mm:ss.ZZZ
2011-12-07 11:36:11.751 Catalogo-V1[13741:207] date: (null)
  • 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-27T09:09:47+00:00Added an answer on May 27, 2026 at 9:09 am

    I think that instead of the format string yyyy-MM-dd HH:mm:ss.ZZZ, you will want yyyy-MM-dd HH:mm:ss.SSS.

    ZZZ will be a timezone value, whereas SSS is fractional seconds.

    See the Unicode documentation (linked from Apple’s docs on Data Formatting)

    Edit: one other thing: you don’t need to have the line NSDate *dateFromString = [[NSDate alloc] init];. Just call NSDate *dateFromString = [dateFormatter dateFromString:fecha];. The date formatter will allocate the date object as it needs to.

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

Sidebar

Related Questions

I have a string 14-Sep-2011 In need to convert this 14th Sept. This date
I have a string I need to convert back to a date. I can
I have a string containing a local date/time and I need to convert it
I have a string that I need to convert to the equivalent array of
I have an xml document object that I need to convert into a string.
Let's say I have an integer that I need to convert to a string
I have a string which I need to verify if it's a Country code.
I need a function to check a date with boolean. I have a String
I have the following code: DateTime pickerDate = Convert.ToDateTime(pickerWakeupDate.SelectedDate); string enteredStr = pickerDate.ToShortDateString() +
I have the following std::string '2010-08-10T23:59:00' and I need to convert it to 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.