Skip to content

Instantly share code, notes, and snippets.

@Slackwise
Last active February 5, 2024 00:39
Show Gist options
  • Save Slackwise/aee0b7258cb17a05ddad to your computer and use it in GitHub Desktop.
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.
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