himanth himanth - 1 year ago 85
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download