Skip to content

Instantly share code, notes, and snippets.

@rslay
Created April 17, 2021 02:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rslay/50859d2f1521ad7013ce1503b025c57a to your computer and use it in GitHub Desktop.
Save rslay/50859d2f1521ad7013ce1503b025c57a to your computer and use it in GitHub Desktop.
Script to set datetime localtime $TZ Variable
# Adjust the number 2 to suit your needs, or use a different timezone like PDT
export TZ=EST2EDT
# Get the current time from an internet site (clearly, not a reliable method) and store into file
wget "https://www.utctime.net/" -O curtime.txt && grep "td>UTC</td" curtime.txt|head -n 1|cut -f 4 -d '>'|cut -f 1 -d '<'|sed -e 's/T/ /g'|
# Remove the Z character (for me, on a weird Unix distro, this causes the date command issues)
sed -e 's/Z//g' > curtime_fmt.txt &&
# Take a few seconds, just in case, because some versions of wget theoretically(?) might not be blocking
sleep 3 &&
# Set time value from file
date -s "$(cat curtime_fmt.txt)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment