himanth himanth - 3 months ago 11
iOS Question

Change current time to Indian standard time

I am getting current date by using this

NSDate *currDate;
currDate = [NSDate date];

But If user opens my app from other country also the currDate should be Indian time only.

How can I do this?


Check if this helps, there could be multiple ways of approaching this - but this is readable -

NSDate *currentDate = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterLongStyle];
[dateFormatter setTimeZone:[NSTimeZone timeZoneWithName:@"Asia/Kolkata"]];
NSString *indianTimeZone = [dateFormatter stringFromDate:currentDate];
NSLog(@"%@", indianTimeZone);

I learned about "Asia/Kolkata" by logging -

NSLog(@"%@", [NSTimeZone knownTimeZoneNames]);

Also, checkout this answer, I like this approach.