mskw
mskw

Reputation: 10358

NSDateComponent giving me day incremented by 1

I know this is a time zone problem, but I don't know how to solve this.

I have a NSDate = 2013-07-29 01:10:01 +0000

When I do a NSDateComponent, the day component shows 28!

I'm in EST time zone right now, but why doesn't it just show 29 straight up?? Is this a bug?

If not, how do i fix this to show it properly? Or is it already proper?

Thanks.

Upvotes: 0

Views: 70

Answers (1)

Charles A.
Charles A.

Reputation: 11143

The problem is that your calendar instance is currently set to your time zone, so it is interpreting the date as 5 hours prior to what it would be in GMT (which is what you pasted in your question).

To resolve this issue you should set the timeZone property on the calendar you are using to get the date components out of the date. Something like this will probably do the trick, assuming your calendar variable is named calendar:

calendar.timeZone = [NSTimeZone timeZoneForSecondsFromGMT:0];

Upvotes: 3

Related Questions