Skip to content

Instantly share code, notes, and snippets.

@hiranp
Last active July 29, 2024 19:44
Show Gist options
  • Save hiranp/1ec2923a8b207932dd3f671eca35a0c9 to your computer and use it in GitHub Desktop.
Save hiranp/1ec2923a8b207932dd3f671eca35a0c9 to your computer and use it in GitHub Desktop.
Calculate time 4 hours earlier in bash
#!/bin/bash
# Get the current time in UTC
CURRENT_TIME=$(date -u +'%FT%T')
EARLIER=$(date -u -d '-1 hour' +'%FT%T')
echo "Current Time: $CURRENT_TIME"
echo "One Hour Earlier: $EARLIER"
# Calculate four hours earlier
FOUR_HOURS_EARLIER=$(date -u -d '-4 hours' +'%FT%T')
echo "CURRENT_TIME: $CURRENT_TIME"
echo "ONE_HOUR_EARLIER: $EARLIER"
echo "FOUR_HOURS_EARLIER: $FOUR_HOURS_EARLIER"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment