This is a really basic question, I guess, but I can't seem to find the answer in any of my books.
Suppose I have a date, created like this:
NSDate *today = [NSDate date];
But I want to change the time part of 'today' to '00:00:00'. How can I do this?
---- added ----
I tried this:
NSDateComponents *components = [[NSDateComponents alloc] init];
[components setDay:11];
[components setMonth:5];
[components setYear:2013];
[components setHour:0];
[components setMinute:0];
[components setSecond:0];
NSCalendar *calendar = [NSCalendar currentCalendar];
NSDate *startDate = [calendar dateFromComponents:components];
NSLog(@"Current date: %@", startDate);
But NSLog prints out this:
Current date: 2013-05-11 04:00:00 +0000
I'm guessing this has something to do with my NY timezone?
-- ANSWER --
Here is the answer for anyone who is looking for it. The trick to eliminate the 04:00:00
from the time is to set the timezone to GMT:
[calendar setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
-- REVISED ANSWER --
But you might actually want the local time -- for example, if you need to find a record in core data by date, and the stored date is in local time -- so you might not want to set the timezone to GMT, after all.