'\" te .\" Copyright (c) 2004, 2011, Oracle and/or its affiliates.All rights Reserved. .\" Copyright 1989 AT&T .\" Copyright (c) 1992, X/Open Company Limited All Rights Reserved .\" Sun Microsystems, Inc. gratefully acknowledges The Open Group for permission to reproduce portions of its copyrighted documentation.Original documentation from The Open Group can be obtained online at http://www.opengroup.org/bookstore/. .\" The Institute of Electrical and Electronics Engineers and The Open Group, have given us permission to reprint portions of their documentation.In the following statement, the phrase "this text" refers to portions of the system documentation.Portions of this text are reprinted and reproduced in electronic form in the Sun OS Reference Manual, from IEEE Std 1003.1, 2004 Edition, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 6, Copyright (C) 2001-2004 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group.In the event of any discrepancy between these versions and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document.The original Standard can be obtained online at http://www.opengroup.org/unix/online.html.This notice shall appear on any product containing this material. .TH date 1 "2011 年 1 月 20 日" "SunOS 5.11" "用户命令" .SH 名称 date \- 写入日期和时间 .SH 用法概要 .LP .nf \fB/usr/bin/date\fR [\fB-u\fR] [+\fIformat\fR] .fi .LP .nf \fB/usr/bin/date\fR [\fB-a\fR [-]\fIsss.fff\fR] .fi .LP .nf \fB/usr/bin/date\fR [\fB-u\fR] [ [\fImmdd\fR] \fIHHMM\fR | \fImmddHHMM\fR [\fIcc\fR] \fIyy\fR] [\fI\&.SS\fR] .fi .LP .nf \fB/usr/xpg4/bin/date\fR [\fB-u\fR] [+\fIformat\fR] .fi .LP .nf \fB/usr/xpg4/bin/date\fR [\fB-a\fR [-]\fIsss.fff\fR] .fi .LP .nf \fB/usr/xpg4/bin/date\fR [\fB-u\fR] [ [\fImmdd\fR] \fIHHMM\fR | \fImmddHHMM\fR [\fIcc\fR] \fIyy\fR] [\fI\&.SS\fR] .fi .SH 描述 .sp .LP \fBdate\fR 实用程序将日期和时间写入到标准输出,或者尝试设置系统日期和时间。缺省情况下,将写入当前日期和时间。 .sp .LP 支持指定月份和工作日名称的本机语言转换。用于某种语言的月份和工作日名称基于由环境变量 \fBLC_TIME\fR 指定的语言环境。请参见 \fBenviron\fR(5)。 .sp .LP 下面是 \fBC\fR 语言环境的缺省形式: .sp .in +2 .nf \fI%a %b %e %T %Z %Y\fR .fi .in -2 .sp .LP 例如, .sp .in +2 .nf Fri Dec 23 10:10:42 EST 1988 .fi .in -2 .sp .SH 选项 .sp .LP 支持以下选项: .sp .ne 2 .mk .na \fB\fB-a\fR [ \fB-\fR ] \fI sss.fff\fR\fR .ad .RS 21n .rt 将时间少量调整 \fIsss\fR.\fI fff\fR 秒(\fIfff\fR 表示一秒的几分之一)。此调整可以为正,也可以为负。系统的时钟将加快或变慢,直到改变了所指定的秒数。只有超级用户可以调整时间。 .RE .sp .ne 2 .mk .na \fB\fB-u\fR\fR .ad .RS 21n .rt 以格林威治标准时间(GMT 通用时间)显示(或设置)日期,绕过通常会执行的与本地时间之间的转换。 .RE .SH 操作数 .sp .LP 支持下列操作数: .sp .ne 2 .mk .na \fB\fB+\fR\fIformat\fR\fR .ad .RS 11n .rt 如果参数以 \fB+\fR 开头,则 \fBdate\fR 的输出是将 \fIformat\fR 和当前时间传递给 \fBstrftime()\fR 得到的结果。\fBdate\fR 使用 \fBstrftime\fR(3C) 手册页上列出的转换规范,并根据使用的是 \fB/usr/bin/date\fR 还是 \fB/usr/xpg4/bin/date\fR 确定针对 \fB%C\fR 的转换规范: .sp .ne 2 .mk .na \fB\fB/usr/bin/date\fR\fR .ad .RS 22n .rt 语言环境的日期和时间表示形式。这是 \fBdate\fR 的缺省输出。 .RE .sp .ne 2 .mk .na \fB\fB/usr/xpg4/bin/date\fR\fR .ad .RS 22n .rt 世纪(年份除以 100 并截断到整数),采用十进制数字形式 [00-99]。 .RE 此外,date 支持 \fI%N\fR,%N 将自新纪元(\fB1970 年 1 月 1 日 00:00:00 UTC\fR)算起的当前时间的纳秒部分表示为一个十进制数字 [\fB000000000-999999999\fR]。转换规范可以接受一个可选的标志字符、一个可选的字段宽度,或者同时接受两者(与在 \fBstrftime()\fR 中规定一样),但有以下差异:如果指定的字段宽度小于 9,则实际的日期输出将仅包含指定的纳秒数位(从左端算起)。 .sp 字符串始终以换行符终止。包含空格的参数必须用引号括起来,请参见“示例”部分\fB\fR。 .RE .sp .ne 2 .mk .na \fB\fImm\fR\fR .ad .RS 11n .rt 月份数 .RE .sp .ne 2 .mk .na \fB\fIdd\fR\fR .ad .RS 11n .rt 月中的天数 .RE .sp .ne 2 .mk .na \fB\fIHH\fR\fR .ad .RS 11n .rt 小时数(24 小时系统) .RE .sp .ne 2 .mk .na \fB\fIMM\fR\fR .ad .RS 11n .rt 分钟数 .RE .sp .ne 2 .mk .na \fB\fISS\fR\fR .ad .RS 11n .rt 秒数 .RE .sp .ne 2 .mk .na \fB\fIcc\fR\fR .ad .RS 11n .rt 世纪(年份除以 100 并截断到整数),采用十进制数字形式 [00-99]。例如,对于 1988 年,\fIcc\fR 是 \fB19\fR,对于 2007 年,它是 \fB20\fR。 .RE .sp .ne 2 .mk .na \fB\fIyy\fR\fR .ad .RS 11n .rt 年数的最后两位数。如果未指定世纪 (\fIcc\fR),则范围 \fB69–99\fR 中的值指的应当是从 1969 年到 1999 年(包含),范围 \fB00–68\fR 中的值指的应当是从 2000 年到 2068 年(包含)。 .RE .sp .LP 月份、天、年份数和世纪可以省略;当前值将应用为缺省值。例如,以下条目: .sp .in +2 .nf example% \fBdate 10080045\fR .fi .in -2 .sp .sp .LP 将日期设置为 10 月 8 日 上午 12:45。缺省年份是当前年份,因为未提供年份。系统以 GMT 执行运算。\fBdate\fR 会执行与本地标准时间和夏时制时间之间的转换。只有超级用户可以更改日期。在成功设置日期和时间后,\fBdate\fR 将根据缺省格式显示新日期。\fBdate\fR 命令使用 \fBTZ\fR 来确定正确的时区信息;请参见 \fBenviron\fR(5)。 .SH 示例 .LP \fB示例 1 \fR生成输出 .sp .LP 以下命令: .sp .in +2 .nf example% \fBdate '+DATE: %m/%d/%y%nTIME:%H:%M:%S'\fR .fi .in -2 .sp .sp .LP 生成以下输出 .sp .in +2 .nf DATE: 08/01/76 TIME: 14:45:05 .fi .in -2 .sp .LP \fB示例 2 \fR设置当前时间 .sp .LP 以下命令将当前时间设置为 \fB12:34:56\fR: .sp .in +2 .nf example# \fBdate 1234.56\fR .fi .in -2 .sp .LP \fB示例 3 \fR以格林威治标准时间设置另一个时间和日期 .sp .LP 以下命令将日期设置为 2000 年 1 月 1 日上午 12:30: .sp .in +2 .nf example# \fBdate -u 010100302000\fR .fi .in -2 .sp .sp .LP 这显示为: .sp .in +2 .nf Thu Jan 01 00:30:00 GMT 2000 .fi .in -2 .sp .SH 环境变量 .sp .LP 有关影响 \fBdate\fR 执行的以下环境变量的说明,请参见 \fBenviron\fR(5):\fBLANG\fR、\fBLC_ALL\fR、\fBLC_CTYPE\fR、\fBLC_TIME\fR、\fBLC_MESSAGES\fR 和 \fBNLSPATH\fR。 .sp .ne 2 .mk .na \fB\fBTZ\fR\fR .ad .RS 6n .rt 确定用来写入时间和日期的时区,除非指定了 \fB-u\fR 选项。如果未设置 \fBTZ\fR 变量并且未指定 \fB-u\fR,则将使用系统缺省时区。 .RE .SH 退出状态 .sp .LP 将返回以下退出值: .sp .ne 2 .mk .na \fB\fB0\fR\fR .ad .RS 6n .rt 成功完成。 .RE .sp .ne 2 .mk .na \fB\fB>0\fR\fR .ad .RS 6n .rt 出现错误。 .RE .SH 属性 .sp .LP 有关下列属性的说明,请参见 \fBattributes\fR(5): .SS "/usr/bin/date" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/core-os _ CSIEnabled(已启用) .TE .SS "/usr/xpg4/bin/date" .sp .sp .TS tab() box; cw(2.75i) |cw(2.75i) lw(2.75i) |lw(2.75i) . 属性类型属性值 _ 可用性system/xopen/xcu4 _ CSIEnabled(已启用) _ 接口稳定性Committed(已确定) _ 标准请参见 \fBstandards\fR(5)。 .TE .SH 另请参见 .sp .LP \fBstrftime\fR(3C)、\fBattributes\fR(5)、\fBenviron\fR(5)、\fBstandards\fR(5) .SH 诊断 .sp .ne 2 .mk .na \fB\fBno permission\fR\fR .ad .RS 18n .rt 您不是超级用户并且您试图更改日期。 .RE .sp .ne 2 .mk .na \fB\fBbad conversion\fR\fR .ad .RS 18n .rt 设置日期时使用了错误的语法。 .RE .SH 附注 .sp .LP 如果您尝试将当前日期设置为标准时区和备用时区发生变化的某个日期(例如,夏时制时间开始或结束的日期),并且您尝试将时间设置为介于标准时间的结束与备用时间的开始(或备用时间的结束与标准时间的开始)之间的某个时间,则结果不可预测。 .sp .LP 从窗口环境内使用 \fBdate\fR 命令来更改日期可能会导致不可预测的结果并且不安全。在多用户模式下更改日期(也就是说,在窗口系统外,如果日期被快速地改来改去)可能也不安全。用于修改日期的建议方法是 '\fBdate\fR \fB-a\fR'。 .sp .LP 在 Solaris 上,不允许将系统时间设置为或者任其发展为超出 \fB2038 年 1 月 19 日 03:14:07 UTC\fR 的时间。