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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:14:03+00:00 2026-06-02T16:14:03+00:00

I guess my question would be more like: what is the difference between dateString1

  • 0

I guess my question would be more like: what is the difference between dateString1 and dateString2?

NSString *dateString = [NSString stringWithFormat:@"2012-07-09 04:10:00 +0000"];
NSString *dateString2 = [NSString stringWithFormat:[[list objectAtIndex:0] nsDate]];
NSArray *chunks = [dateString2 componentsSeparatedByString:@">"];
NSString *correct = [chunks objectAtIndex:0];

NSLog(@"StingOne:%@", dateString);
NSLog(@"InvalidTwo:%@", dateString2);
NSLog(@"StingTwo:%@", correct);

NSDate *datefromString = [[NSDate alloc] init];
NSDate *datefromString2 = [[NSDate alloc] init];

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


datefromString = [formater dateFromString:dateString];
datefromString2 = [formater2 dateFromString:correct];

NSLog(@"1st DATE:%@", datefromString);
NSLog(@"2nd DATE:%@", datefromString2);

As you can see in this code I am converting two strings into NSDate. This is what I get in my log console:

2012-04-24 17:22:09.586 NSString2NSDate[20233:f803] StingOne:2012-07-09 04:10:00 +0000
2012-04-24 17:22:09.589 NSString2NSDate[20233:f803] InvalidTwo:2012-07-19 23:00:00 +0000>
2012-04-24 17:22:09.590 NSString2NSDate[20233:f803] StingTwo:2012-07-19 23:00:00 +0000
2012-04-24 17:22:09.594 NSString2NSDate[20233:f803] 1st DATE:2012-07-09 04:10:00 +0000
2012-04-24 17:22:09.595 NSString2NSDate[20233:f803] 2nd DATE:(null) 

I can’t get my mind on what is the problem here because both strings are outputting correct NSLog as strings. I notice that dateString2 parsed from xml had “>” at the end which is definitely added somewhere in the process so I removed it but still NSDate is (null).

Is this string encoding problem and how do I correct this?

XML file encoding is utf-8.

Thank you.

  • 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-02T16:14:04+00:00Added an answer on June 2, 2026 at 4:14 pm

    hh indicates hours in the range 1-12 and HH indicates hours in the range 0-23. So you should use HH instead of hh to be able to parse 23:00:00.

    NSDateFormatter *formater = [[NSDateFormatter alloc] init];
    [formater setDateFormat:@"yyyy-MM-dd HH:mm:ss z"];
    
    NSDate *datefromString = [formater dateFromString:dateString];
    NSDate *datefromString2 = [formater dateFromString:correct];
    

    Also note that I’ve used only one NSDateFormatter. It is not an error to use two, but the second one is not necessary.

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

Sidebar

Related Questions

Question is old and i guess has no 100% right answer. But would like
Okay guess this question looks a lot like: What is the best way to
This is more of an I'd like to know kind of question, than a
I guess the question title sums it up. Is there a time when it
I guess this question will sound familiar, but I am yet another programmer baffled
I have a HashMap (although I guess this question applies to other collections) of
Simple question I guess, I want to use PHP to write an update to
I guess the real question is: If I don't care about dirty reads, will
This is very basic magento question i guess. I want to first get all
This is a simple question,I guess, but I couldn't figure it out. How do

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.