Display or set date and timeoptions not BSD not mac os |
date [-jnRu] [-d x⃓y datestring| --date= datestring] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] …
date -d n -t minutes_west
date
[-nu]
[-r file
] [ +format]
[-f | fmt date | --file=fileOfDates
[[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]
date
[[[[[cc]yy]mm]dd]hh]mm[.ss] set system time
The default format is: | "%a %b %e %H:%M:%S %Z %Y"
|
sample output: | Sat Dec 31 18:09:28 EST 2021 |
Useful forms: | |||||||||||
export TODAY=`date +%y%m%d` quotes are unneeded as format does not include space etc | echo $TODAY |
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 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
If
Attempting to set or adjust a date to an invalid day fails with return code of 1. For example:
If the date is adjusted to a value that does not exist (due to day light savings time, for example March 26, 01:30 BST 2000
in the Europe/London timezone), the date will be adjusted forwards in units of one hour until it reaches a valid time |
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 |
---|