Display or set date and timeGreen
options
not BSD

java Script

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

Useful forms:
export TODAY=`date +%y%m%d`echo $TODAY
131108
export yymmdd=`date +"%y%m%d"` echo $yymmdd
130915
export LOG=`date +log/%y%m%d.%H%M` echo $LOG
log/130720.1859

myscript1 >> $LOG
myscript2 >> $LOG

export title=`date +"Report Date: %m/%d %H:%M"` report Date: 07/20 18:56

touch `date +%y-%m-%d_%H:%M`
creates file named now.

Example: 13-12-31_23:59

format codes
(arranged by function, not alphabetically, composite formats)

   N.B. If used in crontab command fields, % must be escaped.

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

%m mm month (0112) (how to blank padded?? ie ' 1, 2, 3' vs '01,02,03' ?? )
%b abbreviated month (JanDec)
%h (same as:%b)
%B full month, variable length (January…December)
%d dd (01…31), %e ( 1…31)
%C cc century (00…99)
%y yy two digit year (00…99)
%Y ccyy year (1970)
%g 2-digit year corresponding to the %V week number %G 4-digit
%F %Y-%m-%d (2013-02-24)
%D mm/dd/yy %x mm/dd/yy
hours
%I (01…12) %H (00…23)
%l (1…12)  %k (0…23)
%p AM or PM upper case (blank in many locales)   %P am or pm lower case
%M MM minutes (00…59)
%S SS second (00…60) The 60 is necessary to accommodate a leap second
%R 24-hour (23:59),
%T hh:mm:ss 24-hour ( 11:53:41 )     %X %H:%M:%S (11:56:05 AM)      %r 12-hour (11:26:20 AM )
%N ¬⌘ nanoseconds since last second (000000000..999999999)
     Use sed to restrict the output to milliseconds:
date +%S.%N|sed "s/......$//" 26.123
%c date and time (Sat Nov 04 12:02:33 EST 1989 )
%j day of year (001…366)
%u day of week (1…7); 7 represents Sunday mtwtfss
%w                    (0…6); 0 represents Sunday smtwtfs
%a abbreviated weekday (Sun…Sat)
%A full weekday, variable length (Sunday…Saturday)
%U week number Sunday as first day of week (00…53)
%W week number Monday as first day of week (00…53)    %V (01…53)
%z -zzzz RFC-822 style numeric timezone (-0500)
%:z +hh:mm numeric timezone ( -04:00)
%::z +hh:mm:ss numeric time zone ( -04:00:00)
%:::z numeric time zone with : to necessary precision (-04, +05:30)
%Z time zone (EDT) nothing if no time zone is determinable
$TZ timezone, unless overridden by command line parameters. Default: the setting from /etc/localtime is used.
     > hexdump -e  '"%_p"' -s 0x4DB -n 7   /etc/localtime
     EDT.EST

     > echo $TZ
     US/Eastern
%s seconds since 00:00:00 1970-01-01 UTC
           1264434947 was Mon Jan 25 10:55:57 EST 2010
           1402410634 was Tue Jun 10 10:29:44 EDT 2014
    To convert %s value like 1212642879 use date -d "1970-01-01 1212642879 sec utc"

Example usage: include in .profile:
export login_s=`date +%s`

echo ' $(((`date +%s` - $login_s)/60)) minutes since login.'

literals: %n newline ; %% percent; %t horizontal tab

By default, date pads numeric fields with zeroes.

GNU (not BSD) date recognizes modifiers between % and a numeric:
- (hyphen) do not pad the field           _ (underscore) pad the field with spaces
 examples:

%_H == %k       %-m/%-d/%y 1/2/50

Options

-d
-de=string
display time described by string
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 2010 
To convert seconds (for example 1212642879) use:
> date -d "1970-01-01 1212642879 sec utc"
Thu Jun 5 01:14:39 EDT 2008

-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. Dec 31 19:00:00 EST 1969 )

-u Display or set the date in UTC (universal) time.
Without the + , date uses the argument for setting the system's date if user has sufficient authorization.
[-u|
--utc|
--universal]
[MMDDhhmm[[CC]YY][.ss]]
The only valid option for the this form specifies Coordinated Universal Time.
-u GMT ex: Sat Feb 5 14:49:42 GMT 2005
--utc
--universal Coordinated Universal Time local TZ Sat Feb  5 09:49:59 EST 2005

-ITIMESPEC
--iso-8601[=timespec] output in ISO 8601 format.
timespec precision : date | hours | minutes | seconds
> date --iso-8601=date
2010-08-23
> date --iso-8601=hours
2010-08-23T21-0400
> date --iso-8601=minutes
2010-08-23T21:05-0400
> date --iso-8601=seconds
2010-08-23T21:05:53-0400
-R
--rfc-822
output RFC-822 compliant date string
example: Sat Feb 15 09:50:23 EST 2005
--help display help and exit
--version output version information and exit
-r file
--reference=file
output modification date/time of file
         > date -r 0test 
         Thu Aug 19 18:05:09 EDT 2010

         > date -r arp.1.html +"%y%m%d_%H%M"
         140630_1810
date [[[[[cc]yy]mm]dd]hh]mm[.ss]
set system time

see also

strftime

java script functions From w3schools.com
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