Skip to content

Instantly share code, notes, and snippets.

@thesuhu
Last active May 1, 2023 17:07
Show Gist options
  • Save thesuhu/1293dd2c3654d49200b3ae2464c5a2f5 to your computer and use it in GitHub Desktop.
Save thesuhu/1293dd2c3654d49200b3ae2464c5a2f5 to your computer and use it in GitHub Desktop.
Get UTC Time From Internet
#!/bin/bash
# get UTC date
date -u -d "$(curl -sI google.com | grep -i '^date:' | cut -d' ' -f2-)"
# get local date from UTC
date -d "$(curl -sI google.com| grep -i '^date:'|cut -d' ' -f2-)"
# sync local date from UTC
sudo date -s "$(date -d "$(curl -sI google.com | grep -i '^date:' | cut -d' ' -f2-)" '+%Y-%m-%d %H:%M:%S')"
# UTC vs local
date -d "$(curl -sI google.com| grep -i '^date:'|cut -d' ' -f2-)" && date
date -u -d "$(curl -sI google.com| grep -i '^date:'|cut -d' ' -f2-)" && date -u
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment