Is there an way to get a time very precisely in iPhone.? Currently i am trying with the ios
NTp client
Here . I am getting almost 600 milliseconds difference while comparing with different divices . Even i am not worrying about the accurate time like ntp
, I want to show same time with milliseconds
in different devices.
Asked
Active
Viewed 1,585 times
3

Linus Caldwell
- 10,908
- 12
- 46
- 58

Sat
- 1,616
- 3
- 22
- 40
-
Are you forming the date from a dateString send from Server? – Anupdas Apr 25 '13 at 06:19
-
http://stackoverflow.com/questions/1490537/gmt-time-on-iphone – Arpit Kulsreshtha Apr 25 '13 at 06:32
-
Yes .I am getting the time from different ntp server right now . – Sat Apr 25 '13 at 06:34
-
1The ios-ntp client notes that it does not fully implement the NTP protocol and does not intend to achieve much more than ~ 1s accuracy. If you want greater accuracy, you'll probably need to use a full ntp client or implement your own. It's a very challenging problem; I'm not aware of an existing solution. I would probably start by extending the ntp-ios code, since it already does part of the work. – Rob Napier Apr 25 '13 at 20:13
-
Thanks Rob .. Please let me know if you find any solution . – Sat Apr 26 '13 at 07:47
2 Answers
1
This is simple way to do this go through it :-
+ (NSDate *) GMTNow
{
NSDate *sourceDate = [NSDate date];
NSTimeZone* currentTimeZone = [NSTimeZone localTimeZone];
NSInteger currentGMTOffset = [currentTimeZone secondsFromGMT];
[sourceDate dateByAddingTimeInterval:currentGMTOffset];
return sourceDate;
}

Arpit Kulsreshtha
- 2,452
- 2
- 26
- 52
-
-
No its depends on your location and universal time. It always give exact time rather your system time changed. – Arpit Kulsreshtha Apr 25 '13 at 06:40
-
Thanks for your replay ..Still its not working for me .Its getting 3-4 second difference in different device :( – Sat Apr 25 '13 at 09:37
-
Can you tell me for which purpose you required such precise timing. Please elaborate. If answer is helpful to upvote it. – Arpit Kulsreshtha Apr 25 '13 at 09:42
-
want to trigger some event in precise time ( playing audio ,video kind of stuff ) in different devices . In case of audio playing in different devices user can easily identify the difference . – Sat Apr 25 '13 at 09:47
-
Means you want to trigger a event on multiple device which run that event simultaneously, I am getting you right r not. – Arpit Kulsreshtha Apr 25 '13 at 09:59
-
Yeah .you are right .but the start time of the event in all devices should be accurate . – Sat Apr 25 '13 at 10:03
-
let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/28897/discussion-between-arpit-kumar-and-sat-v-can-shake-the-world) – Arpit Kulsreshtha Apr 25 '13 at 12:56
-
`-addTimeInterval:` is deprecated, should use `-dateByAddingTimeInterval:` – Tricertops Apr 25 '13 at 20:32