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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:49:04+00:00 2026-05-28T00:49:04+00:00

I have a method, + (NSDate *) convertToDateFrom:(NSString *) dateString { if (dateString ==

  • 0

I have a method,

+ (NSDate *) convertToDateFrom:(NSString *) dateString
{
    if (dateString == nil || [dateString isEqual:@""]) return nil; //return nil if dateString is empty
    NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setDateFormat:@"EEEE, dd MMMM yyyy HH:mm"];

    NSDate *date = [df dateFromString:dateString];

    return date;
}

When I pass,

@"Monday, 21 November 2011 17:01" //Passed string

It returns a wrong date,

2011-11-21 23:14:00 +0000 // Output

I am not sure whether I am using those flags correctly or NSDateFormatter isn’t properly converting my string to date.

Am I doing something wrong?

Thanks

  • 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-28T00:49:05+00:00Added an answer on May 28, 2026 at 12:49 am

    The +0000 at the end of the date indicates GMT. All dates are stored relative to GMT; when you convert a date to a string or vice versa using a date formatter, the offset to your time zone is included. You can use NSDateFormatter’s -setTimeZone: method to set the time zone used.

    In short, you’re not doing anything wrong in your code. Use [df stringFromDate:date]; to see that the date is correct. (You can also use NSDate’s -descriptionWithCalendarFormat:timeZone:locale:.)

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

Sidebar

Related Questions

I have a method that can return either a single object or a collection
i have this code in my overridden drawRect method NSDate *date = [NSDate date];
lets say I have aclass @interface Foo :NSobject { NSstring *a; NSDate *b; }
I have the following NSString : NSString * dateString = @2012-01-24T14:59:01Z; I want to
I am having problems with NSDateFormatter 's dateFromString method. I have the following date:
UPDATED I have this method in Objective C: -(NSDate*)roundTo15:(NSDate*)dateToRound { int intervalInMinute = 15;
I have method in a class that I need to make sure is only
I have a method which takes params object[] such as: void Foo(params object[] items)
I have class method that returns a list of employees that I can iterate
I have a method that where I want to redirect the user back to

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.