Created
February 11, 2021 07:34
-
-
Save deepakduggirala/63bc678d750ece7d5a7cce0aa7581a95 to your computer and use it in GitHub Desktop.
Bash TimeZone Converter - MacOS
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 | |
TZ='CST6CDT' date | |
TZ='EST' date | |
TZ='UTC' date | |
date | |
while [[ $# -gt 0 ]] && [[ "$1" == "--"* ]] ; | |
do | |
opt="$1"; | |
shift; #expose next argument | |
case "$opt" in | |
"--" ) break 2;; | |
"--cst2ist" ) | |
CST_TIME="$1"; shift;; | |
"--cst2ist="* ) # alternate format: --first=date | |
CST_TIME="${opt#*=}";; | |
"--ist2cst" ) | |
IST_TIME="$1"; shift;; | |
"--ist2cst="* ) | |
IST_TIME="${opt#*=}";; | |
"--optional" ) | |
OPTIONAL="$optional_default";; #set to some default value | |
"--optional=*" ) | |
OPTIONAL="${opt#*=}";; #take argument | |
*) echo >&2 "Invalid option: $@"; exit 1;; | |
esac | |
done | |
echo '' | |
if [ -n "$CST_TIME" ] | |
then | |
echo "$CST_TIME CST in IST is" | |
TZ="Asia/Calcutta" gdate --date 'TZ="CST6CDT"'$CST_TIME | |
fi | |
echo '' | |
if [ -n "$IST_TIME" ] | |
then | |
echo "$IST_TIME IST in CST is" | |
TZ="CST6CDT" gdate --date 'TZ="Asia/Calcutta"'$IST_TIME | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tz --cst2ist 03:30 --ist2cst 15:00
Thu Feb 11 01:33:26 CST 2021
Thu Feb 11 02:33:26 EST 2021
Thu Feb 11 07:33:26 UTC 2021
Thu Feb 11 13:03:26 IST 2021
03:30 CST in IST is
Thu Feb 11 15:00:00 IST 2021
15:00 IST in CST is
Thu Feb 11 03:30:00 CST 2021