Bash datetime (manipulate)
1 2 3 4 5 6 7
| NAME date - print or set the system date and time
SYNOPSIS date [OPTION]... [+FORMAT] date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]
|
We want to manipulate the datetime change.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| YYYYMMDD="20210315" Next_day=$(date +%Y%m%d -d "$YYYYMMDD + 1 day")
Next_day=$(date +%Y-%m-%d -d "$YYYYMMDD + 1 day")
Next_day=$(date +%Y-%m-%d_%H:%M:%S -d "$YYYYMMDD + 1 day")
Next_day=$(date +%Y-%m-%d_%H:%M:%S -d "$YYYYMMDD + 1 hour")
Next_day=$(date +%Y-%m-%d_%H:%M:%S -d "$YYYYMMDD + 1 min")
Next_day=$(date +%Y-%m-%d_%H:%M:%S -d "$YYYYMMDD + 1 second")
Next_day=$(date +%Y-%m-%d_%H:%M:%S -d "$YYYYMMDD + 1 day + 1 hour + 1 min + 1 second")
|
1 2 3
| YYYYMMDD="2021-04-15" Next_day=$(date +%Y-%m-%d_%H:%M:%S -d "$YYYYMMDD + 1 day + 1 hour + 1 min + 1 second")
|
1 2 3
| YYYYMMDD="2017-01-19 00:05:01" Next_day=$(date +%Y-%m-%d_%H:%M:%S -d "$YYYYMMDD + 1 day + 1 hour + 1 min + 1 second")
|
for loop
1 2 3 4 5
| YYYYMMDD="2024-06-02" for gfsfile in $(seq 0 1 28); do next_day=$(date +%Y%m%d%H -d "$YYYYMMDD + ${gfsfile} day") echo $next_day done
|
To seperate
1 2 3 4 5 6
| FCST_DURATION="000_17:00:00"
fcst_DD=${FCST_DURATION:0:3} fcst_hh=${FCST_DURATION:4:2} fcst_mm=${FCST_DURATION:7:2} fcst_ss=${FCST_DURATION:10:2}
|