- 论坛徽章:
- 0
|
date Linux and Unix 命令手册
本命令手册以实用,简洁为原则,对于已经消化的内容,不附加详细的注解。
磁针石
联系方式:
QQ:37391319 gmail and gtalk: xurongzhong@gmail.com
参考资料
l
《Unix 技术手册》
l
Solaris 8 date 命令帮助
常用用法
*Solaris 8 帮助中的实例,分行显示日期和时间
bash-2.03# date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'
DATE: 11/23/07
TIME:09:31:50
Linux
的命令帮助没有这种实例,可见参考Solaris的更好。
* 设置日期和时间, 设置为2000年1月1日 16:59
bash-2.03# date 010116592000
Sat Jan 1 16:59:00 CST 2000
*Solaris 8 帮助中的实例,设置时间
bash-2.03# date 1234.56
Sat Jan 1 12:34:56 CST 2000
*获取年月日
bash-2.03# date +%y-%m-%d
07-11-23
命令参考
*Solaris 8 date
命令参考
bash-2.03# man date
Reformatting page. Please Wait... done
User Commands
date(1)
NAME
date - write the date and time
SYNOPSIS
/usr/bin/date [ -u ] [ +
format ]
/usr/bin/date
[ -a
[ - ] sss.fff ]
/usr/bin/date [ -u ] [ [ mmdd ]
HHMM | mmddHHMM
[ cc ]
yy ] [ .SS ]
/usr/xpg4/bin/date [ -u ] [ +
format ]
/usr/xpg4/bin/date [ -a [ - ]
sss.fff ]
/usr/xpg4/bin/date [ -u ] [ [ mmdd ]
HHMM | mmddHHMM
[
cc ] yy ] [
.SS ]
DESCRIPTION
The date utility writes the date and time to standard output
or attempts to set the system date and time. By default, the
current date and time will be written.
Specifications of native language translations
of month and
weekday names are
supported. The month and weekday
names
used for a language are based on the locale specified by the
environment variable LC_TIME; see
environ(5).
The following is the default form for the "C" locale:
%a %b %e %T %Z %Y
for example,
Fri Dec 23 10:10:42 EST 1988
OPTIONS
The following options are supported:
-a [-]sss.fff
Slowly adjust the
time by sss.fff
seconds (fff
represents fractions of a second). This adjustment can
be positive or negative. The system's
clock will be
sped up or
slowed down until it has drifted
by the
number of seconds specified. Only the
super-user may
adjust the time.
-u Display (or set) the
date in Greenwich
Mean Time
(GMT-universal time), bypassing
the normal conversion
to (or from) local time.
SunOS 5.8 Last change: 20 Apr 1999 1
User Commands
date(1)
OPERANDS
The following operands are supported:
+format
If the argument begins with +, the output of date
is
the result of passing format and the current time to
strftime(). date uses the conversion
specifications
listed on the
strftime(3C) manual
page, with the
conversion specification for %C determined by whether
/usr/bin/date or /usr/xpg4/bin/date is used:
/usr/bin/date
Locale's date and time
representation. This is the
default output for date.
/usr/xpg4/bin/date
Century (a year divided by 100
and truncated to an
integer) as a decimal number [00-99].
The string is always terminated with a NEWLINE. An argument
containing blanks must be quoted; see the EXAMPLES section.
mm Month number
dd Day number in the month
HH Hour number (24 hour system)
MM Minute number
SS Second number
cc Century minus one
yy Last 2 digits of the year
number
The month, day, year, and century may be omitted; the
current values are applied as defaults. For example,
the following entry:
example% date 10080045
sets the date to Oct 8, 12:45 a.m.
The current year is
the default because
no year is supplied. The system
operates in GMT. date takes care of the conversion to
and from local
standard and daylight time. Only the
super-user may change the date.
After successfully
setting the date and time, date
displays the new date
SunOS 5.8 Last change: 20 Apr 1999 2
User Commands
date(1)
according to the default format. The date command uses
TZ to determine the correct time zone information; see
environ(5).
EXAMPLES
Example 1: Generating output
The command
example% date '+DATE: %m/%d/%y%nTIME:%H:%M:%S'
generates as output
DATE: 08/01/76
TIME: 14:45:05
Example 2: Setting the current time
The command
example# date 1234.56
sets the current time to 12:34:56.
ENVIRONMENT VARIABLES
See environ(5) for descriptions of the following environment
variables that affect
the execution of
date: LC_CTYPE,
LC_TIME, LC_MESSAGES, and NLSPATH.
TZ Determine the timezone in
which the time and date are
written, unless the -u option is specified. If the TZ
variable is not set and the -u is not
specified, the
system default timezone is used.
EXIT STATUS
The following exit values are returned:
0 Successful completion.
>0 An error occurred.
ATTRIBUTES
See attributes(5) for descriptions of the following
attri-
butes:
/usr/bin/date
SunOS 5.8 Last change: 20 Apr 1999 3
User Commands
date(1)
____________________________________________________________
| ATTRIBUTE TYPE |
ATTRIBUTE VALUE |
|_____________________________|_____________________________|
|
Availability |
SUNWcsu |
|_____________________________|_____________________________|
|
CSI |
enabled |
|_____________________________|_____________________________|
/usr/xpg4/bin/date
____________________________________________________________
| ATTRIBUTE TYPE |
ATTRIBUTE VALUE |
|_____________________________|_____________________________|
|
Availability |
SUNWxcu4 |
|_____________________________|_____________________________|
|
CSI |
enabled |
|_____________________________|_____________________________|
SEE ALSO
strftime(3C),
attributes(5), environ(5), XPG4(5)
DIAGNOSTICS
no permission
You are not the super-user and you tried to change the
date.
bad conversion
The date set is syntactically incorrect.
NOTES
If you attempt to set the current date to one of the
dates
that the standard and alternate time zones change (for exam-
ple, the date that daylight time is starting or ending), and
you attempt to
set the time
to a time in the interval
between the end of standard time and the
beginning of the
alternate time (or
the end of the alternate time and
the
beginning of standard time), the results are unpredictable.
Using the date command from within windowing environments to
change the date
can lead to unpredictable results
and is
unsafe. It may also be unsafe in the multi-user mode,
that
is, outside of a
windowing system, if the date is changed
rapidly back and forth. The recommended method of
changing
the date is 'date -a'.
SunOS 5.8 Last change: 20 Apr 1999 4
bash-2.03#
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21908/showart_428969.html |
|