1

We can get the current date and time by using NSDate but it returns the device data and time.

NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init]; 
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSLog(@"%@",[dateFormatter stringFromDate:[NSDate date]]);

If the user has changed the date in the device then NSDate returns the changed date. Is there any way to get the current date even though the user has changed the date?

Some may suggest to get the date from the server but i think this approach will not work for us because user can use our app in offline. After installing our app for the first time and user is in offline then we cannot check the date and time from server since user do not have any internet connectivity. We can only get the exact date once he is online.

Any suggestions will be really appreciated

Madhu
  • 439
  • 2
  • 14
  • There are some limitations for this workaround! When you open the app, generate the current timestamp and store it locally! And use that time stamp everytime, and modify it according to the time returned by NSdate by adding or deleting the mins/hours/secs! – Teja Nandamuri May 12 '17 at 13:47
  • We don't have control over the date time changes in device. So it would be great if it can be handle by server side. – Minkle Garg May 12 '17 at 13:50
  • @TejaNandamuri If the user has already changed the date and opened the app then if we are storing it as current date, based on this stored date if i will do any adding or deleting the mins/hours/secs this will give the wrong values since the stored date is wrong. Your suggestion will not help in this case. Any alternate way? – Madhu May 12 '17 at 13:54
  • That is why I said there are some limitations to this one! Show a pop up at the beginnning syaing "If you change the date before opening this app, please enter the actual time now and take the user input! :P " – Teja Nandamuri May 12 '17 at 13:56

0 Answers0