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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:55:17+00:00 2026-05-28T20:55:17+00:00

I use the following code to create an NSDate from string: NSDateFormatter *df =

  • 0

I use the following code to create an NSDate from string:

NSDateFormatter *df = [[[NSDateFormatter alloc] init] autorelease];
[df setTimeZone:[NSTimeZone defaultTimeZone]];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSLog(@"The date from string: %@", [df dateFromString:@"2012-01-31 01:32:30"]);

What I see in the result is:

The date from string: 2012-01-31 07:32:30 +0000

This is obviously not correct.
Do you know why it adds 6 hours to my result date and how to fix it?

  • 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-28T20:55:18+00:00Added an answer on May 28, 2026 at 8:55 pm

    NSLog of dates is not a good way to display dates with time zones, instead use an NSDateFormatter to get a string for the time zone desired.

    NSDate is UTC based, the one true time that can be correctly displayed for any timezone with NSDateFormatter.

    From the Apple NSDate docs:

    To parse strings containing dates and to generate string
    representations of a date, you should use an instance of
    NSDateFormatter using the methods dateFromString: and stringFromDate:
    respectively—see “Date Formatters” for more details.

    Example code:

    NSDateFormatter *df = [[NSDateFormatter alloc] init];
    [df setTimeZone:[NSTimeZone defaultTimeZone]];
    [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date = [df dateFromString:@"2012-01-31 01:32:30"];
    NSLog(@"The date from string: %@", date);
    
    NSString *stringFromDate = [df stringFromDate:date];
    NSLog(@"stringFromDate: %@", stringFromDate);
    

    NSLog output:

    The date from string: 2012-01-31 06:32:30 +0000
    stringFromDate: 2012-01-31 01:32:30

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

Sidebar

Related Questions

I use the following code try to create an array of string vectors, I
I'm trying to use the following code to create a zip file from a
I can use the following code to create image from UIView. However the same
I use the following code to create countdowns in Javascript. n is the number
I use the following code to create a folder mymir and a file .nomedia
We currently use the following code to create an email in Outlook so that
I know that to create a file in c++ we use following code #include
I use the following code in the FormCreate event handler to create a system
I am trying to use the following code to create a list of client
I'm trying to use the following code to create a new SalesInvoice based on

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.