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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T00:10:23+00:00 2026-06-17T00:10:23+00:00

I guess I don’t understand how to properly manage timezone. I have a date

  • 0

I guess I don’t understand how to properly manage timezone. I have a date object that is generated from various methods, including UIDatepicker, which uses the device timezone for the UI and generates a date object with UTC+0000.

I’m also trying to extract just the 4-digit year from the date object, but I’m getting an unexpected result. I thought the problem was that I needed to apply a timezone to the date formatter, but that doesn’t seem to have helped. Here is my code:

NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
NSTimeZone *currentTimeZone = [NSTimeZone localTimeZone];
[dateFormat setTimeZone:currentTimeZone];
[dateFormat setDateFormat:@"YYYY"];
NSLog(@"About to use self.displayedDate: %@",self.displayedDate);
NSString *gregorianYear = [dateFormat stringFromDate:self.displayedDate];
NSLog(@"Calculated Gregorian year: %@ from date %@",gregorianYear,self.displayedDate);

I’m currently in CST. When I run this, I get the following output:

2013-01-06 21:22:47.168 293 Calendar[4835:907] About to use self.displayedDate: 2012-12-31 03:22:26 +0000
2013-01-06 21:22:47.171 293 Calendar[4835:907] Calculated Gregorian year: 2013 from date 2012-12-31 03:22:26 +0000

The date in my app is originally set from the current date/time. Then I use the UIDatePicker control configured only for dates to set the date to December 30 2012 (that’s what displays on the UIDatePicker control). The return value from the datepicker is plugged directly into the code that produced the above output. It seems obvious to me that it should produce 2012 instead of 2013, so I must be missing something.

  • 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-17T00:10:25+00:00Added an answer on June 17, 2026 at 12:10 am

    Don´t use the format symbols: “YYYY”! use “yyyy” instead!

    “YYYY” is the week year, which is not what you want!

    See also Converting NSString to NSDate adds one year in some cases

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

Sidebar

Related Questions

I guess I don't understand how the Windows Command Prompt evaluates equality. I have
I don't understand this paradigm I guess? For a small single server or development
I guess that the # Net column is the most interesting, although I don't
Guess that I have a TextView that I want to update it in some
I guess I don't fully understand how destructors work in C++. Here is the
I hate writing error condition code. I guess I don't have a good approach
I'm having trouble bringing back data from my PHP file. I guess I don't
I'm just wondering what the point of regions are. I guess I don't understand
This might be a very vague question but I guess I don't really understand
I understand the idea of this error. But I guess I don't understand how

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.