Objective-C Tips & Trick - Prioregroup.com
[Objective-C] Convert GMT date to Italian date
       
back

// GMT date (NSString)
NSCharacterSet *charset = [[NSCharacterSet characterSetWithCharactersInString:@"0123456789-:+ "] invertedSet];
NSString *date = [[your_gmt_date componentsSeparatedByCharactersInSet:charset] componentsJoinedByString:@""];
if (![date containsString:@"+0000"])
	date = [date stringByAppendingString:@" +0000"];
    
// GTM date (NSData)
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZZZ"];
NSDate *gmt_date = [dateFormatter dateFromString:date];
    
// Italian date (NSString)
NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init];
[outputFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Europe/Rome"]];
[outputFormatter setLocale:[NSLocale localeWithLocaleIdentifier:@"it_IT"]];
[outputFormatter setDateFormat:@"dd-MM-yyyy HH:mm:ss"];
NSString *s_italianDate = [outputFormatter stringFromDate:gmt_date];

// Italian date (NSDate)
NSDate *italianDate = [NSDate dateWithTimeInterval:[outputFormatter.timeZone secondsFromGMT] sinceDate:gmt_date];






Copyright © 1996-2018 Centro Studi Informatica di Danilo Priore. All rights reserved. P.I.10149810581.
prioregroup.com