在 Solaris 系统上设置/调整(硬件)时钟的添加信息

使用 UTC 时钟信息检查系统上的当前日期/时间

# date -u
Wed Jan 20 21:54:52 GMT 2016

以格林威治标准时间设置另一个时间和日期的示例

以下命令将日期设置为 Thu Jan 21 10:15:00 GMT 2016

# date -u 072110152016
Thu Jan 21 10:15:00 GMT 2016
# date    
Thu Jan 21 11:16:46 BST 2016
# date -u
Thu Jan 21 10:16:54 GMT 2016

问题

在 Solaris 操作系统 (OS) 中,默认时区在哪里设置 ?

欢迎来到之路教程(on itroad-com)

Solaris 10 操作系统及以下

  1. 默认时区在 /etc/TIMEZONE 配置文件中设置(符号链接到 /etc/default/init )。
# cat /etc/default/init
#
# Copyright 1992, 1999-2002 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#
#ident  "@(#)init.dfl   1.7     02/12/03 SMI"
#
# This file is /etc/default/init.  /etc/TIMEZONE is a symlink to this file.
# This file looks like a shell script, but it is not.  To maintain
# compatibility with old versions of /etc/TIMEZONE, some shell constructs
# (i.e., export commands) are allowed in this file, but are ignored.
#
# Lines of this file should be of the form VAR=value, where VAR is one of
# TZ, LANG, CMASK, or any of the LC_* environment variables.  value may
# be enclosed in double quotes (") or single quotes (').
#
TZ=US/Mountain
...
  1. 要更改系统时区,请编辑 /etc/TIMEZONE 文件并更改 TZ 变量的值。
    例如:
TZ=US/Eastern
  1. 我们必须重新启动系统以使时区更改生效。

可以在 /usr/share/lib/zoneinfo 目录中找到有效时区/本地时间值的列表

例如目录 /usr/share/lib/zoneinfo 中的“欧洲/柏林”

# ls -1d /usr/share/lib/zoneinfo/Europe/[A-Z]*
Europe/Amsterdam
Europe/Andorra
Europe/Athens
-- lines omitted -
Europe/Zaporozhye
Europe/Zurich
# ls -1d /usr/share/lib/zoneinfo/US/[A-Z]*
US/Alaska
US/Aleutian
US/Arizona
US/Central
-- lines omitted -
US/Mountain
US/Pacific
US/Pacific-New
US/Samoa

其他大陆/国家也类似:

Africa/
America/
Asia/
-- lines omitted -

仅为一个特定命令设置/更改时区 (TZ) 的示例

以下命令仅为一个特定命令设置 TZ=Europe/London

# TZ=Europe/London date
Wed Jan 20 22:31:17 BST 2016
# TZ="US/Central" date
Wed Jan 20 16:35:33 CDT 2016
# TZ="US/Central" date '+%Y-%m-%d %H:%M:%S'
2016-07-20 16:35:35

为每个用户设置时区 (TZ) 变量

可以在 .profile 或者 .login 中为每个用户设置 TZ 变量。
例如

# vi ~/.profile
TZ=Europe/London

为每个非全局区域 (NGZ) 设置时区 (TZ) 变量

自从在 Solaris 10 中引入 Zones 以来,就一直需要能够让 Zones 设置自己的时间。
可以像选择全局区域一样选择本地非全局区域中的默认 TIMEZONE。

Solaris 11 操作系统及更高版本

  1. 默认时区定义为“svc:/system/timezone:default” SMF 服务的属性:
# svcs timezone
STATE          STIME    FMRI
online         Aug_22   svc:/system/timezone:default
# svcprop timezone:default |grep localtime
timezone/localtime astring US/Eastern
  1. 要更改默认时区,请使用 svccfg,然后使用 svcadm 命令刷新服务。
    例如:
# svccfg -s timezone:default setprop timezone/localtime = astring: US/Mountain
# svcadm refresh timezone:default
  1. 或者,可以使用 zic 命令更改默认时区。
    这是更改时区的合理方法;当我们尝试使用错误的值更改时区时,它将立即失败。
    如果我们使用 svccfg 并且可能会出现拼写错误,那么我们可能没有意识到这一点并且该命令仍然可以工作。
    通过 zic 修改时区的示例:
# /usr/sbin/zic -l US/Mountain
  1. 另一种修改默认时区的方法是使用“nlsadm set-timezone”。
    例子:
// ensure the package nls-administration is installed
# pkg list nls-administration
NAME (PUBLISHER) VERSION IFO
system/locale/nls-administration 0.5.11-0.175.3.0.0.26.2 i-
// get the currently selected default timezone
# nlsadm get-timezone
timezone=Europe/London
// select the default timezone
# nlsadm set-timezone US/Eastern
Setting SMF property timezone/localtime with value: 'US/Eastern' ...
Successfully set
// confirmation
# nlsadm get-timezone
timezone=US/Eastern
# date
Wed Jan 20 16:58:42 EDT 2016
如何在 Solaris 10,11 中设置时区
日期:2020-09-17 00:15:13 来源:oir作者:oir