0

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?

raurora
  • 3,623
  • 1
  • 22
  • 29
Himanth
  • 2,381
  • 3
  • 28
  • 41

1 Answers1

1

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.

Community
  • 1
  • 1
raurora
  • 3,623
  • 1
  • 22
  • 29