Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Observe changes of system date/time in macOS

I'm an iOS developer coming to the Mac. On iOS, we can implement the applicationSignificantTimeChange: method in our app delegate or register for the UIApplicationSignificantTimeChangeNotification notification to react to changes in the system time.

I cannot seem to find an equivalent on the Mac. How can I observe significant changes in the system time (examples: user changes time (zone), switch from/to daylight savings) in macOS (other than starting a timer that fires every second or so)?

like image 810
Ole Begemann Avatar asked Jan 21 '11 15:01

Ole Begemann


People also ask

How to change the date and time on a Mac?

1. Click on the Apple icon in the top Menu bar on your Mac and then click on the System Preferences option in the drop-down menu. 2. On the System Preferences screen, click on Date & Time option.

How to set Time Zone automatically on Mac?

Click on the Apple icon in the top Menu-bar on your Mac and then click on the System Preferences option in the drop-down menu. 2. On the System Preferences screen, click on Date & Time option. 3. On the Date & Time screen, first click on the Time Zone tab and then enable Set Time Zone Automatically option (See image below). 4.

How to fix macOS system date is incorrect?

during macOS install/upgrade to macOS Catalina, Mojave, High Sierra, or technically any other macOS Software this blog post is for you. The above error indicates that most likely your Mac System Date is incorrect. Boot into macOS Recovery again by restarting your Mac and holding CMD + R keys together.

How do I set the date and time on my computer?

You can have the date and time set automatically using a network time server, or set your computer’s date and time manually. Be sure your time is correct so time stamps on emails, messages, and files are correct. On your Mac, choose Apple menu > System Preferences, then click Date & Time .


1 Answers

You need to track NSCurrentLocaleDidChangeNotification, NSSystemClockDidChangeNotification, NSSystemTimeZoneDidChangeNotification and NSWorkspaceDidWakeNotification and then re-schedule timers for all significant timestamps such as midnight.

Mac Catalyst does support UIApplicationSignificantTimeChangeNotification.

like image 149
Kentzo Avatar answered Oct 05 '22 23:10

Kentzo