-1

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.

Gowtham K
  • 75
  • 2
  • 9

2 Answers2

2

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...

Jogendra.Com
  • 6,394
  • 2
  • 28
  • 35
0

NSDate does not have a time zone, so your NSDates are not in the UK time zone. An NSDate is an absolute time reference. That means that if you call [NSDate date] and someone on the other side of the world does it at exactly the same time, you both get the same result.

Time zones only exist when displaying dates, but they're not part of NSDate.

If you want to display a date in Mexico's time zone, you would do something like this:

NSDate *date = // your NSDate here

NSTimeZone *myZone = [NSTimeZone timeZoneWithName:@"America/Mexico_City"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeZone:myZone];

NSString *dateString = [dateFormatter stringFromDate:date];

If you want to get the date for some other time zone, just change the first line to use a different zone. For example, in India you might use

NSTimeZone *myZone = [NSTimeZone timeZoneWithName:@"Asia/Kolkata"];
Tom Harrington
  • 69,312
  • 10
  • 146
  • 170