You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

NAME

date - print the system date and time

SYNOPSIS

date [FORMAT]

DESCRIPTION

Display the current time in the given FORMAT. If FORMAT is not specified, the default system format is used.

Date and time formats are specified by date and time pattern strings. Within date and time pattern strings, unquoted letters from 'A' to 'Z' and from 'a' to 'z' are interpreted as pattern letters representing the components of a date or time string. Text can be quoted using single quotes (') to avoid interpretation. "''" represents a single quote. All other characters are not interpreted; they are simply copied into the output string during formatting or matched against the input string during parsing.

ATTRIBUTE OPTIONS

The following pattern letters are defined:

G Era designator (e.g., AD)
y Year (e.g., 1996; 96)
M Month in year (e.g., July; Jul; 07)
w Week in year (e.g., 27)
W Week in month (e.g., 2)
D Day in year (e.g., 189)
d Day in month (e.g., 10)
F Day of week in month (e.g., 2)
E Day in week (e.g., Tuesday; Tue)
a Am/pm marker (e.g., PM)
H Hour in day (0-23) (e.g., 0)
k Hour in day (1-24) (e.g., 24)
K Hour in am/pm (0-11) (e.g., 0)
h Hour in am/pm (1-12) (e.g., 12)
m Minute in hour (e.g., 30)
s Second in minute (e.g., 55)
S Millisecond (e.g., 978)
z Time zone (e.g., Pacific Standard Time; PST; GMT-08:00)
Z Time zone (e.g., -0800)

The default system format is "EEE MMM dd HH:mm:ss z yyyy".

EXAMPLES

The following examples show how date and time patterns are interpreted. The given date and time are 2013-06-08 14:52:37 local time in the U.S. Pacific Time time zone.

> date "yyyy.MM.dd G 'at' HH:mm:ss z" 
Output: 2013.06.08 AD at 14:52:37 PDT  
> date "EEE, MMM d, ''yy" 
Output: Sat, Jun 8, '13
> date "h:mm a" 
Output: 2:52 PM
> date "hh 'o''clock' a, zzzz"
Output: 02 o'clock PM, Pacific Daylight Time
> date "K:mm a, z"
Output: 2:52 PM, PDT 
> date "yyyyy.MMMMM.dd GGG hh:mm aaa" 
Output: 02013.June.08 AD 02:52 PM
> date "EEE, d MMM yyyy HH:mm:ss Z" 
Output: Sat, 8 Jun 2013 14:52:37 -0700
> date "yyMMddHHmmssZ"
Output: 130608145237-0700
> date "yyyy-MM-dd'T'HH:mm:ss.SSSZ"
Output: 2013-06-08T14:52:37.375-0700



  • No labels