2

Is it possible to get the NTP or accurate timestamp without internet connection? I cannot take/don't trust device timestamp with [NSDate date] as it can be modify by user and my apps will be hacked by just modifying the system date & time.

Apart from this, instead of obtain accurate timestamp, is there any way to check the system date has changed by user or not set as "Automatically".

Thanks & Regards,

Weng

weng
  • 21
  • 4
  • Sadly, CLLocationManager doesn't provide this (even though GPS chipset has true time information). One way (maybe not the best one) would be to use some kind of [Network Time Protocol](http://en.wikipedia.org/wiki/Network_Time_Protocol) – Rok Jarc May 17 '12 at 11:59

1 Answers1

-1

If you want to gather the current date in relation to a specific time zone, you can use something along the lines of:

    //create calendar
NSCalendar *calendar = [NSCalendar currentCalendar];

//set calendar time zone
[calendar setTimeZone:[NSTimeZone timeZoneWithAbbreviation:@"UTC"]];

//gather date components
NSDateComponents *components = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSHourCalendarUnit | NSMinuteCalendarUnit) fromDate:[NSDate date]];

It's a little convoluted, but there still seems to be an issue with NSDate on iOS with regards to daylight savings so this has saved me a lot of time ( pun not intended :P ).

Zack Brown
  • 5,990
  • 2
  • 41
  • 54