SHARE
TWEET

Convert GMT date to Italian date

priore Nov 23rd, 2015 (edited) 552 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // GMT date (NSString)
  2. NSCharacterSet *charset = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789-:+ "] invertedSet];
  3. NSString *date = [[your_gmt_date componentsSeparatedByCharactersInSet:charset] componentsJoinedByString:@""];
  4. if (![date containsString:@"+0000"])
  5.         date = [date stringByAppendingString:@" +0000"];
  6.    
  7. // GTM date (NSData)
  8. NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  9. [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZZ"];
  10. NSDate *gmt_date = [dateFormatter dateFromString:date];
  11.    
  12. // Italian date (NSString)
  13. NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
  14. [outputFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Europe/Rome"]];
  15. [outputFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"it_IT"]];
  16. [outputFormatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
  17. NSString *s_italianDate = [outputFormatter stringFromDate:gmt_date];
  18.  
  19. // Italian date (NSDate)
  20. NSDate *italianDate = [NSDate dateWithTimeInterval:[outputFormatter.timeZone secondsFromGMT] sinceDate:gmt_date];
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top