Date: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 45: Line 45:
=File Name Format=
=File Name Format=


<pre>
date +'%y.%m.%d-%H.%M.%S'
date +'%y.%m.%d-%H.%M.%S'
 
</pre>
or
 
date +'%Y.%m.%d'


=Setting Date and Time=
=Setting Date and Time=

Revision as of 14:06, 14 April 2020

External

Internal

Overview

date +'%m/%d/%y %H:%M:%S'

Output:

03/07/11 16:07:17

Double quotes also work:

date +"%m/%d/%y %H:%M:%S"

This also works:

date "+%m/%d/%y %H:%M:%S"

Output Patterns

%s seconds since epoch (?)

AM/PM

date +'%m/%d/%y %I:%M:%S %p'

Year

Short year (14) %y

Long year (2014) %Y

File Name Format

date +'%y.%m.%d-%H.%M.%S'

or

date +'%Y.%m.%d'

Setting Date and Time

date 08311650

sets the date for 08/31 current year, time 16:50.

Getting the Time in Seconds

date '+%s'

Elapsed Time in Seconds

local t0=$(date '+%s')
sleep 2
local t1=$(date '+%s')
local elapsed=$(expr ${t1} - ${t0})
echo "elapsed seconds: ${elapsed}"