Monday, September 23, 2013

NSDate - few important things

If your program logic makes decisions based on time here are few things you need to remember.
  • [NSDate date] will give you the GMT time and date. But this is calculated using the current device time. If the device time is wrong this value is also wrong.
  • [[NSTimeZone systemTimeZone] name] will give the device time zone. e.g. Asia/Colombo
  • [[NSTimeZone systemTimeZone]secondsFromGMT] will give the number of seconds from GMT. e.g. 19800
  • If you want to get the device time use [NSDate dateWithTimeInterval:[[NSTimeZone systemTimeZone]secondsFromGMT] sinceDate:[NSDate date]]

No comments: