Date: Difference between revisions

From Leo's Notes
This page was last edited on 24 February 2017, at 04:17.
some initial information on formatting
 
m Text replacement - "{{highlight|lang=bash" to "{{highlight|lang=terminal"
Line 3: Line 3:
== Formatting ==
== Formatting ==
{{code|date}} can be formatted using the {{code|+}} argument followed by the format string. For example:
{{code|date}} can be formatted using the {{code|+}} argument followed by the format string. For example:
{{highlight|lang=bash|code=
{{highlight|lang=terminal|code=
# date +"%T"
# date +"%T"
11:26:25
11:26:25

Revision as of 04:17, 24 February 2017

The date unix utility returns the time as a text string.

Formatting

date can be formatted using the + argument followed by the format string. For example:

# date +"%T"
11:26:25

Here are some common formats.

Format Output
%T 12:34:56 (ie: HH:MM:SS)
%r 09:30:55 PM (ie: HH:MM:SS XX)
%m-%d-%y 12-02-15 (ie: MM:DD:YY)
%m-%d-%Y 12-02-2015 (ie: MM:DD:YYYY)
%D 12/02/2015 (ie: MM/DD/YYYY)