Wonder if I've found a bug with NSDateComponents.
The time between the date and time zone to the switching calculated using NSDateComponents, it is possible to get wrong on the simulator (device is not tested).
It seems that this offset is fine, but going in the wrong direction. Either, or I'm basically a misunderstanding (which is always a distinct possibility)
Sample: one time UTC in addition to the system time (mine Mexico, UTC -05 other area: 00) set After setting the Mexican time zone Therefore The code uses NSLog output So everything seems fine to me. get
// components to the existing full-time NSDateComponents * components = [[NSCalendar currentCalendar] components: (NSYearCalendarUnit | NSDayCalendarUnit | NSMonthCalendarUnit | NSMinuteCalendarUnit | NSHourCalendarUnit | NSSecondCalendarUnit) fromDate: [NSDate date]]; // Get the calendar, which defines the time zone in the current time zone components.calendar = [NSCalendar currentCalendar]; // Set the time zone to the UTC component. Calendars Timezone = [nstimeZone timezoneWebb: @ "UTC"]; // Log in NSLog (@ "Date Time:% @:% @", components.calendar.timeZone, [date of the components]); // Output (for example): "Date on Time Zone: GMT Offset (GMT) 0: 2013-06-21 14:55:56 +0000" // It should be full time, so any changes in time zone set the relative // timezone // this should be offset in the local time zone components.calendar.timeZone (just behind Mexico, 5 hours) = [NSTimeZone localTimeZone]; // Log in NSLog (@ "Date Time:% @:% @", components.calendar.timeZone, [date of the components]); // output (such as): "At the time zone local time zone (America / Mexico_City (CDT) offset -18,000 (Daylight)): 2013-06-21 19:55:56 +0000" Mexico should be considered, otherwise the second date should be five hours behind the first one?
components.calendar.timeZone
component represents (in your example)
2013-06- 21 14:55:56 Mexican time zone
[date of the components] returns a
NSDate for that time.
description
NSDate , and it always prints the point in time in GMT time which That
2013-06-21 19:55:56 +0000
No comments:
Post a Comment