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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T08:40:44+00:00 2026-06-09T08:40:44+00:00

I have a NSDate object. Let’s say it represents 1-10-2011 NSDate *date = [df

  • 0

I have a NSDate object. Let’s say it represents “1-10-2011”

NSDate *date = [df dateFromString:@"2011-10-01 00:00:00"];

That date translates into “2011-09-30 22:00:00” because of my timezone.

Question: How do I get a new Date object representing “2011-10-01 00:00:00” in my local timezone?

  • 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-09T08:40:45+00:00Added an answer on June 9, 2026 at 8:40 am

    NSDate only represents an absolute point in time. It has no concept of timezone or calendar. When you create a NSDate instance it is just a number of seconds since January 1st 2001 GMT! It does not matter if you are in New York, Tokyo, Barcelona or Jerusalem.

    At your example, you instance the NSDate based on GMT, but [date description] (used in NSLog) translates it into your local time. There you have the mismatch.

    So there are two parts to consider:

    1. NSDate creation using NSCalendar and NSTimeZone

    If you are creating a date manually you should specify the calendar (2012 in Gregorian, but 5772 in Hebrew) and time zone (22PM London time, but 7AM Sydney time).

    // Use the user's current calendar and time zone
    NSCalendar *calendar = [NSCalendar currentCalendar];
    [calendar setTimeZone: [NSTimeZone systemTimeZone]];
    
    // Specify the date components manually (year, month, day, hour, minutes, etc.)
    NSDateComponents *timeZoneComps=[[NSDateComponents alloc] init];
    [timeZoneComps setHour:22];
    [timeZoneComps setMinute:0];
    [timeZoneComps setSecond:0];
    // ... year, month, ...
    
    // transform the date compoments into a date, based on current calendar settings
    NSDate *date = [calendar dateFromComponents:timeZoneComps];
    

    At this point date stores the exact point in time (in seconds) representing the current calendar.

    2. NSDate output using NSDateFormatter

    For a controlled output of your NSDate you need NSDateFormatter, which is used to convert dates into strings.

    Based on Apple NSDateFormatter Class Reference documentation

    There are many attributes you can get and set on a style date
    formatter
    , …
    You are encouraged, however, not to change individual settings. Instead you should accept the default settings established on initialization and specify the format using setDateStyle:, setTimeStyle:

    This is specially important for the output, which is different for every locale. By default NSDateFormatter observes the current user’s locale settings. So the same NSDate could be 22.11.2011 18:33:19, or Nov 22, 2011 6:33:19 PM, or 2011-11-22 下午6:33:19 or even २२-११-२०११ ६:३३:१९ अपराह्, all for the same input and with the same code.

    And the code:

    //  NSDate *date -> NSString *dateString 
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    
    // Medium style date, short style time => "Nov 23, 1937 3:30pm"
    NSString *dateString = [dateFormatter stringFromDate:date];
    

    Or you could transform it using the class method localizedStringFromDate:dateStyle:timeStyle:

    I hope this clarifies the problem.

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

Sidebar

Related Questions

I have an object that I convert into NSData using an NSKeyedArchiver and then
I have an NSDate object created by NSDate *date = [[NSDate alloc] init]; Later,
Let's say that I have a loop that returns a bunch of autoreleased NSData
I have an NSDate object with value for example: 2011-08-26 14:14:51, I want to
I have NSDate object and I need to find from a NSArray (that has
i have an NSDate object from an old date which i am getting from
I have an NSDate object called 'dueDate'. I'm trying to work out how to
I have been working with NSArray s and NSMutableArray s that store NSDate objects
I have strings with dates, and want to parse these into NSDate objects. Is
i have a function to convert into NSDate by using NSDateFormatter . +(NSDate*)getDateFromCurrentTimestamp:(NSString*)currentTimestamp{ //

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.