Search code examples
iosswiftnsdatensdateformatterdevice

How to get device set time in swift/ios?


enter image description here

I want to get time, which user sees in their status bar if they change the time to 24-hour format, or manually select some other timezone with or some other time in Settings, it should be changed in my app as well.


Solution

  • To display the time in accordance with the user's settings, use a DateFormatter whose locale is set to the current locale. To be notified when the user changes the locale settings, register for the locale change notification.