Display or set date and timeoptions not BSD |
date
[-nu]
[-r file
] [ +format]
The default format is: | "%a %b %e %H:%M:%S %Z %Y"
|
sample output: | Sat Feb 5 18:09:28 EST 2005 |
myscript1 >> $LOG
Example:
Useful forms:
export TODAY=`date +%y%m%d` echo $TODAY
131108
export yymmdd=`date +"%y%m%d"` echo $yymmdd
130915
echo $LOG
log/130720.1859
myscript2 >> $LOG
export title=`date +"Report Date: %m/%d %H:%M"` report Date: 07/20 18:56
touch `date +%Y-%m-%d %H:%M:%S` creates file named now
.
format codes(arranged by function, not alphabetically, composite formats)
N.B. If used in | locale: order of date items vary as well as spellings as per language. Examples: LC_ALL=C > date Wed Jun 22 13:18:10 EDT 2016 > export LC_ALL=es_ES # use Spanish (EspaƱol) > date miƩrcoles, 22 de junio de 2016, 13:39:34 EDT |
-d -de=string display time described by | string including some "humand readable" strings like last Thursday and last month
date -d "2010/12/31" Fri Dec 31 00:00:00 EST 2010 date -d "12/31/2010" Fri Dec 31 00:00:00 EST 2010 date -d "2010-12-31 23:58:57" Fri Dec 31 23:58:57 EST 2010 date -d "23:58:57 12/31/2010" Fri Dec 31 23:58:57 EST 2010 date -d "12/31/2010 23:58:57" Fri Dec 31 23:58:57 EST 2010 date -d "12/31/2010 23 sec" Fri Dec 31 00:00:23 EST 2010To convert seconds (for example 1212642879) use:
-e=datefile like | -de once for each line of datefile
BSD(Mac OS X): | -f fmt_str idate [ +fmt] Output | idate default fmt_str is [[[mm]dd]HH]MM[[cc]yy][.ss]
| -j with -f Don't set |
| -s --set=string set system time described by | string
date -s "2010-12-31 23:59:00"
-n don't synchronize the clocks on groups
of machines using the utility | timed (8). By default, if timed is running, date will set the time on all of the machines in the local group. -n inhibites that.
date and time seconds from the Epoch. ( i.e.
|
date
[[[[[cc]yy]mm]dd]hh]mm[.ss]
according to UTC (aka GMT) date object is local getMonth() | 0-11
| getUTCMonth()
| getDate() | day of the month ( 1-31)
| getUTCDate()
| getFullYear() | year yyyy
| getUTCFullYear()
| getHours() | 0-23
| getUTCHours()
| getMinutes() | 0-59
| getUTCMinutes()
| getSeconds() | 0-59
| getUTCSeconds()
| getMilliseconds() | 0-999
| getUTCMilliseconds()
| getDay() | of the week ( 0-6)
| getUTCDay()
| getTime() | milliseconds since 1/1/1970 00:00
| getTimezoneOffset() | minutes between UTC and local
| getYear() | Deprecated. Use the getFullYear() method
| parse() | number of milliseconds since 1/1/1970 00:00 of date string
| set portions of a date object
| setFullYear() | YYYY
| setUTCFullYear()
| setMonth() |
| setUTCMonth()
| setDate() | day of the month
| setUTCDate()
| setHours() |
| setUTCHours()
| setMinutes() |
| setUTCMinutes()
| setSeconds() |
| setUTCSeconds()
| setMilliseconds() |
| setUTCMilliseconds()
| setTime() | Sets a date and time | by adding or subtracting milliseconds to/from 1/1/1970 00:00 setYear() | Deprecated. Use the setFullYear() method
| formatting to string
| toString() | Sat Aug 04 2012 17:09:15 GMT-0400 (EDT)
| toLocaleString() | Sat Aug 4 17:08:41 2012 | Really! YYYY last toISOString()
| 2012-08-04T21:03:51.449Z
| toJSON() | JavaScript Object Notation 2012-08-04T20:27:42.419Z
| toUTCString() | Sat, 04 Aug 2012 21:32:18 GMT
| toDateString() | Sat Aug 04 2012
| toLocaleDateString() | 08/04/2012
| toTimeString() | 17:14:24 GMT-0400 (EDT)
| toLocaleTimeString() | 17:06:00
| toGMTString() | Deprecated. Use the toUTCString() method
| valueOf() | primitive value of a Date object | 1344116221551 UTC(yyyy,mm,dd) | number of milliseconds in | yyyy,mm,dd since 00:00 1/1/1970 according to universal time 1333065600000 |
---|