Search code examples
iosobjective-cnsarraynsdatenstimezone

how to convert Uk time to Mexico time zone


I am having an array in that date are in UK time zone. I want to convert that UK time zone to below country time. I am having two radio button

Mexico (UTC-6)
India - IST (UTC+5.30)

when i click Mexico (UTC-6) radio button my array date are convert to Mexico time zone and when i click India - IST (UTC+5.30) radio button my array date are converted to indian time zone.

my array[0] time zone date is 2015-04-17 10:29:22 +0000 This is in UK time zone. Please help me in coding, This is the first time i am doing time zone process.


Solution

  • Try this may be help full ... In this you need to pass name of timezone

     NSTimeZone* sourceTimeZone = [NSTimeZone timeZoneWithName:@"Europe/London"];
    NSTimeZone* destinationTimeZone = [NSTimeZone timeZoneWithName:@"America/Mexico_City"];
    
    NSDate *yourDate = [NSDate date]; // Please add here your date that you want change .
    //calc time difference
    NSInteger sourceGMTOffset = [sourceTimeZone secondsFromGMTForDate:yourDate];
    
    NSInteger destinationGMTOffset = [destinationTimeZone secondsFromGMTForDate:yourDate];
    NSTimeInterval interval = destinationGMTOffset - sourceGMTOffset;
    
    //set current real date
    NSDate* date = [[NSDate alloc] initWithTimeInterval:interval sinceDate:yourDate];
    

    All time zone list here All iOS TimeZone Try this helpfull...