Last active
February 5, 2024 00:39
-
-
Save Slackwise/aee0b7258cb17a05ddad to your computer and use it in GitHub Desktop.
I hibernate my VMs at work when I'm done, and the time is always off. I can't just sync with w32tm because if I'm more than 24 hours off, it will refuse to sync.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/ntp' # gem install net-ntp | |
# Windows' date command expects MM/DD/YYYY, e.g. 5/15/2009 | |
DATE_FORMAT = '%m/%d/%Y' | |
# Windows' time command expects HH:MM:SS AM/PM, e.g. 5:34:00 PM | |
TIME_FORMAT = '%I:%M:%S %p' | |
# External NTP is now firewalled :( | |
NTP_SERVER = 'MILLDATA' | |
datetime = Net::NTP.get(NTP_SERVER).time | |
system("date #{datetime.strftime(DATE_FORMAT)}") | |
system("time #{datetime.strftime(TIME_FORMAT)}") | |
__END__ | |
until system("w32tm /resync /rediscover") | |
sleep 10 | |
end | |
puts 'Forced time sync completed.' | |
puts 'Press ENTER to close window.' | |
gets # Pause so you can read the output. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment