3

I know it's a repeating a question , but i didn't get solution from those answer's . please can anybody tell me , How do I get GMT in ios , if the device time is wrong also .

Thanks in advance

Shaik Riyaz
  • 11,204
  • 7
  • 53
  • 70

2 Answers2

1

Try the below:

NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.dateFormat = @"yyyy-MM-dd'T'HH:mm";
NSTimeZone *gmtZone = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[dateFormatter setTimeZone:gmtZone];
NSString *timeStamp = [dateFormatter stringFromDate:[NSDate date]];
NSLog(@"%@",timeStamp);
Tarek Hallak
  • 18,422
  • 7
  • 59
  • 68
  • thanks for response , i tried this code but no luck . if we change device time then timestamp value is changing according to that . – Shaik Riyaz Sep 17 '13 at 12:50
  • @RIYAZ i am also getting same problem. do you find any solution for this one? – Hari Babu Oct 14 '14 at 11:20
  • @HariBabu No , i also tried with ntp-ios but no luck . – Shaik Riyaz Oct 14 '14 at 12:22
  • Guys consider to force the user set the accurate time after setting up the application, save this value somewhere maybe NSUserDefaults, I am afraid there is no way to accomplish what you want from client side without connecting a webserves or remote time service. – Tarek Hallak Oct 15 '14 at 08:01
0

You must rely on an external server to achieve this. There is no built in method other than the ones for recovering the local phones time.

Here is a github project where they try to do exactly this for iOS : https://github.com/jbenet/ios-ntp

Tibor Udvari
  • 2,932
  • 3
  • 23
  • 39
  • i tried that , but i am getting some issue with that ,please refer this question http://stackoverflow.com/questions/18845981/ios-ntp-framework-sync-issue – Shaik Riyaz Sep 18 '13 at 05:10