Skip to content

Instantly share code, notes, and snippets.

@arsalanses
Created August 29, 2024 10:16
Show Gist options
  • Select an option

  • Save arsalanses/0420bfc558d8cc2976a003bf3014ae37 to your computer and use it in GitHub Desktop.

Select an option

Save arsalanses/0420bfc558d8cc2976a003bf3014ae37 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -xue
# Synchronize the system clock with an NTP server
sudo ntpdate pool.ntp.org
# Get the current UTC time
current_utc=$(date -u +"%Y-%m-%d %H:%M:%S")
# Convert the current UTC time to a timestamp
current_timestamp=$(date -d "$current_utc" +"%s")
# Calculate the timestamp for UTC minus one hour
new_timestamp=$((current_timestamp - 3600))
# Convert the new timestamp back to a date string
new_date=$(date -d @$new_timestamp +"%Y-%m-%d %H:%M:%S")
# Set the system date and time to the new date
sudo timedatectl set-time "$new_date"
echo "System date and time set to: $new_date"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment