CyberTek - the future at the present!
Google

How to format dates for display in a Linux shell

Posted by: admin (Apr 19)

In the shell you can specify the date format as follows:
date + FORMAT

For example typing:
$ Date +% m-% d-% y "

You get:
04-17-10

If you want the 4-digit year:
$ Date +% m-% d-% y "

You get:
04-17-2010

Step ahead for the current time just type:
$ Date + "% T"

You get:
19:55:04

For superior computing time based on 12 hours:
$ Date + "% r"

You get:
07:56:05 PM

To view the time in HH: MM:
$ Dates + "% H-% M"

You get:
07:56

Complete list of options to format the dates ask:

%%
a literal%
% To
Local's abbreviated weekday name (eg, Sun)
% A

Local's full weekday name (eg, Sunday)

% B
Local's abbreviated month name (eg, Jan)
% B
Local's full month name (eg, January)
% C
Local's date and time (eg, Mon March 3 23:05:25 2005)
% C
century, like% Y, EXCEPT omit last two digits (eg, 21)
% D
Day of month (eg, 01)
% D

dates; Same as% m /% d /% y

% And
day of month, space padded; Same as% _D
% F
Full dates; Same as% Y-% m-% d
% G
last two digits of year of ISO week number (see% G)
% G
Year of ISO week number (see% V); Normally useful only with% V
% H
Same as% b
% H

hour (00 .. 23)

% I
hour (01 .. 12)
% J
Day of year (001 .. 366)
% K
hour (0 .. 23)
% S
hour (1 .. 12)
% M
month (01 .. 12)
% M

minute (00 .. 59)

% N
a newline
% N
nanoseconds (000000000 .. 999999999)
% P
Either's local equivalent of AM or PM, blank if not known
% P
like% p, But lower case
% R
local's 12-hour clock time (eg, 11:11:04 PM)
% R

24-hour hour and minute; Same as% H:% M

% S
Since seconds 01/01/1970 00:00:00 UTC
% S
second (00 .. 60)
% T
Tabbed
% T
time; Same as% H:% M:% S
% U
Day of Week (1 .. 7), 1 is Monday
% U

Week number of year, with Sunday as first day of week (00 .. 53)

% V
ISO week number, with Monday as first day of week (01 .. 53)
% W
Day of week (0 .. 6), 0 is Sunday
% W
Week number of year, with Monday as first day of week (00 .. 53)
% X
Local's date representation (eg, 12/31/1999)
% X
Local's time representation (eg, 23:13:48)
% Y

last two digits of year (00 .. 99)

% Y
year
% Z
+ Hhmm numeric timezone (eg, -0400)
% Z
+ Hh: mm numeric timezone (eg, -04: 00)
%:: Z
+ Hh: mm: ss numeric time zone (eg, -04: 00:00)
%::: Z
numeric time zone with: Necessary to precision (eg, -04, +05:30)
% Z
alphabetic time zone abbreviation (eg, EDT)

Published in: linux , shell , tips

Add A Comment

Spam protection by WP Captcha-Free

Powered by Cybertek - Remote Assistance