Guest User

Untitled

a guest
Apr 21st, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. + (NSDate *)localDateForEventDate:(NSDate *)eventDate
  2. {
  3. NSTimeZone *pacificTimeZone = [NSTimeZone timeZoneWithName:@"America/Los_Angeles"];
  4. NSCalendar *pacificCalendar = [NSCalendar currentCalendar];
  5. [pacificCalendar setTimeZone:pacificTimeZone];
  6.  
  7. unsigned int unitFlags = NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit|NSHourCalendarUnit|NSMinuteCalendarUnit|NSSecondCalendarUnit;
  8. NSDateComponents *eventDateComponents = [pacificCalendar components:unitFlags fromDate:eventDate];
  9.  
  10. NSCalendar *localCalendar = [NSCalendar currentCalendar];
  11. [localCalendar setTimeZone:[NSTimeZone systemTimeZone]];
  12. NSDate *localDate = [localCalendar dateFromComponents:eventDateComponents];
  13.  
  14. return localDate;
  15. }
Add Comment
Please, Sign In to add comment