Difference between revisions of "BASH Time and Date"
From Indie IT Wiki
Plittlefield (talk | contribs) (→Date) |
Plittlefield (talk | contribs) |
||
Line 80: | Line 80: | ||
=== Date Years From Date === | === Date Years From Date === | ||
− | TZ='Europe/London' date -d "1987-01-01+ | + | TZ='Europe/London' date -d "1987-01-01+98 years 11 months 30 days 23 hours 59 minutes 59 seconds" |
[[Category:BASH]] | [[Category:BASH]] | ||
[[Category:Linux]] | [[Category:Linux]] | ||
[[Category:Software]] | [[Category:Software]] |
Latest revision as of 10:56, 30 August 2022
Time Between File Timestamps
NEW
function displaytime () { local T=$1 local D=$((T/60/60/24)) local H=$((T/60/60%24)) local M=$((T/60%60)) local S=$((T%60)) (( $D > 0 )) && printf '%d days ' $D (( $H > 0 )) && printf '%d hours ' $H (( $M > 0 )) && printf '%d minutes ' $M (( $D > 0 || $H > 0 || $M > 0 )) && printf 'and ' printf '%d seconds\n' $S } # displaytime 666 SECONDS=$((stat --printf '%Y' "${FINISHED}"; printf ' - '; stat --printf '%Y\n' "${STARTED}") | bc -lq) && TIMETAKEN=`displaytime $SECONDS` printf "${TITLE}\n\n${INPUTFILESIZE}\n\n${OUTPUTFILESIZE}\n\n${TIMETAKEN}" |mail -s "ffmpeg" paully.littlefield@gmail.com &&
OLD
SECONDS=$((stat --printf '%Y' /home/paully/hb.finished; printf ' - '; stat --printf '%Y\n' /home/paully/hb.started) | bc -lq) && TIMETAKEN=$(date -ud "@$SECONDS" +'$((%s/3600/24)) days %H hours %M minutes %S seconds') && printf "${INPUTFILESIZE}\n\n${OUTPUTFILESIZE}\n\n${SECONDS}\n\n${TIMETAKEN}"
Ping With Time And Date Stamp
ping -i1 -c10 192.168.1.1 | while read pong; do echo "$(date '+%Y-%m-%d-%H:%M:%S') $pong"; done
Time
Checking NTP
timedatectl status
ntpstat
ntpq -pn
Thanks to Cyberciti
Convert Standard Date And Time To Epoch Time
date +%s
Convert Epoch Time To Standard Date And Time
date --date='@1335309835'
Date
Today
date
Yesterday
date -d "yesterday"
Number Of Days Between Two Dates
echo $"(( $(date --date="031122" +%s) - $(date --date="021020" +%s) ))/(60*60*24)"|bc
Number Of Days After
date -d "230 days" or date -d "24 weeks 2 days 4 hour 6 minutes"
Number Of Days Before
date -d "230 days ago" or date -d "24 weeks 2 days 4 hour 6 minutes ago"
Date Years From Date
TZ='Europe/London' date -d "1987-01-01+98 years 11 months 30 days 23 hours 59 minutes 59 seconds"