1

While showing date picker I'm using this code to show today's date

[_datePicker setDate:[NSDate date]];

If I change the device date to some other date the date picker's date is also changing... But I need to show today's date... How to do this

3 Answers3

2

It sounds like what you want to do is to get the date from an authoritative source, like a NTP server.

Some places where you can find open source include "ios-ntp" or "NHNetworkTime", the latter of which (once building within your project) is as simple as doing "NSDate *networkDate = [NSDate networkDate];".

And once you have that date, that's the NSDate object you pass into your _datePicker.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
1

Today's date is always [NSDate date]. If you change device date, device doesn't know anything else. You can try http://www.ntp.org to get Internet Time instead.

mhergon
  • 1,688
  • 1
  • 18
  • 39
0

You can fetch the current Date/Time from the backend server and set it to the Date Picker.