0

I am using the following code to set a date object:

NSDate *date = [NSDate date];
        NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
        NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];
        [components setHour: 18];
        [components setMinute: 00];
        [components setSecond: 00];

        reminderDate = [gregorian dateFromComponents: components];

However, when I NSLog reminderDate I get the following output:

Time: 2012-08-29 17:00:00 +0000

Which is early by one hour, can anyone explain what it is I need to do in order to store the correct date in reminderDate?

Thanks,

Tysin

iMeMyself
  • 1,649
  • 13
  • 28
Jack Nutkins
  • 1,555
  • 5
  • 36
  • 71
  • possible duplicate of [Getting date from \[NSDate date\] off by a few hours](http://stackoverflow.com/questions/8466744/getting-date-from-nsdate-date-off-by-a-few-hours) – jscs Aug 29 '12 at 16:19

1 Answers1

2

What is your time zone? If you notice, the date that you print has +0 time zone, so if your time zone is +1 is all correct.

alfonsomiranda
  • 102
  • 1
  • 9
  • I've tried setting the timezone to use my local time zone with NSTimeZone localTimeZone but there was no change..Currently I am in British Summer Time which is GMT + 1 – Jack Nutkins Aug 29 '12 at 12:00
  • 1
    This means that the date in the log is correct, since it is displayed without the time zone, hence the +0000 – rckoenes Aug 29 '12 at 12:03
  • The date in the log isn't correct, if I do this: NSLog(@"Current Date: %@", [NSDate date]); the date printed is also 1 hour earlier than it should be.. – Jack Nutkins Aug 29 '12 at 12:08
  • Log is correct, NSLog always print with time zone +0. If you time zone is different, convert the date to time zone +0. – alfonsomiranda Aug 29 '12 at 12:14