Last active
July 29, 2024 19:44
-
-
Save hiranp/1ec2923a8b207932dd3f671eca35a0c9 to your computer and use it in GitHub Desktop.
Calculate time 4 hours earlier in bash
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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