Joomla TemplatesWeb HostingWeb Hosting
Linux shell time variables

Format controls the output as follows. The only valid option for the second form (MMDDhhmm[[CC]YY][.ss])will specify Coordinated Universal Time.

Interpreted sequences are:

     Date:
        D    Date in mm/dd/yy format (06/24/13)
        x    Date in standard format for locale (09/24/13 for English-US)
        
     Year:
        C   Century (20 for 2015)
        Y   Year in 4-digit format (2015)
        y   Year in 2-digit format (14)
        G   Same as 'Y'
        g   Same as 'y'
        
     Month: 
        b   Month name - abbreviated (Jan)
        B   Month name - full (January)
        h   Same as 'b'
        m   Month number (09)
        
     Week:
        W  Week of the year (00-52)

        V  Week of the year (01-53)
           If the week containing January 1 has four or
           more days in the new year, then it is considered week 1;
           otherwise, it is week 53 of the previous year, and the next week
           is week 1. Similar to ISO 8601 (but not 100% compliant.)

        U  Same as 'W'
        
     Day:
        a   Day of the week - abbreviated name (Mon)
        A   Day of the week - full name (Monday)
        u   Day of the week - number (Monday = 1)
        d   Day of the month - 2 digits (05)
        e   Day of the month - digit preceded by a space ( 5)
        j   Day of the year - (1-366)
        w   Same as 'u'
        
     Time:
        p   AM or PM
        r   Time in 12-hour format (09:15:36 AM)
        R   Time in 24-hour format - no seconds (17:45)
        T   Time in 24 hour format (17:45:52)
        X   Same as 'T'
        Z   Time offset from UTC (-07) This generally consists of Time Zone+DST
        
     Hour: 
        H   Hour in 24-hour format (17)
        I   Hour in 12 hour format (05)
        k   Same as 'H'
        l   Same as 'I' (Upper-case I = Lower-case L)
        
     Minutes & Seconds:
        M   Minutes (35)
        S   Seconds (05)
        s   Seconds elapsed since January 1, 1970 00:00:00 GMT (Unix time)

Here are the same format codes in alphabetical order:

  %%   a literal %
  %a   locale's abbreviated weekday name (Sun..Sat)
  %A   locale's full weekday name, variable length (Sunday..Saturday)
  %b   locale's abbreviated month name (Jan..Dec)
  %B   locale's full month name, variable length (January..December)
  %c   locale's date and time (Sat Nov 04 12:02:33 EST 1989)
  %d   day of month (01..31)
  %D   date (mm/dd/yy)
  %e   day of month, blank padded ( 1..31)
  %h   same as %b, locale's abbreviated month name (Jan..Dec)
  %H   hour :24 hour(00..23)
  %I   hour :12 hour(01..12)
  %j   day of year (001..366)
  %k   hour :24 hour(00..23)
  %l   hour :12 hour(01..12)
  %m   month (01..12)
  %M   minute (00..59)
  %n   a newline
  %p   locale's AM or PM
  %r   Time, 12-hour (hh:mm:ss [AP]M)
  %s   Seconds since 1970-01-01 00:00:00,  (a GNU extension)
       Note that this value is defined by the localtime system
       call.  It isn't changed by the '--date' option.
  %S   second (00..60)
  %t   a horizontal tab
  %T   Time, 24-hour (hh:mm:ss)
  %U   Week number of year with Sunday as first day of week (00..53)
  %V   Week number of year with Monday as first day of week (01..53)
       If the week containing January 1 has four or
       more days in the new year, then it is considered week 1;
       otherwise, it is week 53 of the previous year, and the next week
       is week 1. Similar to ISO 8601 (but not 100% compliant.)

  %w   day of week (0..6);  0 represents Sunday
  %W   week number of year with Monday as first day of week (00..53)
  %x   locale's date representation (mm/dd/yy)
  %X   locale's time representation (%H:%M:%S)
  %y   last two digits of year (00..99)
  %Y   year (1970...)
  %z   RFC-822 style numeric timezone (-0500) (a nonstandard extension)
       This value reflects the current time zone.
       Is not changed  by the --date option.
  %Z   Time offset from UTC (-07) This generally consists of Time Zone+DST
       Is not changed by the --date option.

By default, date pads numeric fields with zeroes. GNU date recognizes the following modifiers between % and a numeric directive.

- (hyphen) do not pad the field; useful if the output is intended for human consumption.
_ (underscore) pad the field with spaces; useful if you need a fixed number of characters in the output, but zeroes are too distracting.

The - and _ are GNU extensions. Here is an example illustrating the differences:

     date +%d/%m -d "Feb 1"
     => 01/02
     date +%-d/%-m -d "Feb 1"
     => 1/2
     date +%_d/%_m -d "Feb 1"
     =>  1/ 2