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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:34:19+00:00 2026-05-31T07:34:19+00:00

I know that this question was asked a million times, I just can’t find

  • 0

I know that this question was asked a million times, I just can’t find a solution. The problem is: I’m modifying an NSDate to return either the date of the first day in the current month or the date of the first day in the next month. It seems to be working fine except for 1 thing: it gives back the time minus 2 or 3 hours.

Code:

NSCalendar *theCalendar = [NSCalendar currentCalendar];
int comp = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit;
NSDateComponents *theComp = [theCalendar components:comp fromDate:date];
[theComp setTimeZone:[NSTimeZone systemTimeZone]];
switch (roundingMode) {
    case FIRST_OF_MONTH:
        [theComp setDay:1];
        return [theCalendar dateFromComponents:theComp];
    case FIRST_OF_NEXT_MONTH:
        [theComp setMonth:theComp.month+1];
        [theComp setDay:1];
        return [theCalendar dateFromComponents:theComp];
}

Here’s the debugger(gdb) output:

(gdb) po theComp
<NSDateComponents: 0x6e26170>
  TimeZone: Europe/Kiev (EET) offset 7200
  Calendar Year: 2012
  Month: 3
  Day: 1
(gdb) po date
2012-03-12 13:05:22 +0000
(gdb) po [theCalendar dateFromComponents:theComp]
2012-02-29 22:00:00 +0000

Any help would be greatly appreciated.

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-05-31T07:34:20+00:00Added an answer on May 31, 2026 at 7:34 am

    The date is displayed in GMT: 2012-02-29 00:00:00 +0000 is 2012-03-01 22:00:00 +0200. Also don’t forget daylight saving time change which explains why you get a difference of 3 hours sometimes.

    The result date is correct, but the debugger displays it in GMT.

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

Sidebar

Related Questions

I know that this question must have been asked and answered a million times,
I know that this question has been asked million times so my apologies. I
I know that this question have been asked several times. But I can't get
I know that this question has been asked several times and I've read all
I know that this question had already been asked a couple of times before,
I know this question has been asked a million of times here at stackoverflow,
I know that this question has been asked loads of times, but I have
I know that this question might have been asked like 100 times, but, believe
I know this question has been asked a million times in various ways by
I know that this question has been asked many times before in different guises

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.