In Solaris Operating System (OS), where is the default timezone set, and how can it be changed?
Solaris 11 OS and above
1. The default timezone is defined as a property of the “svc:/system/timezone:default” SMF service:
# svcs timezone STATE STIME FMRI online Aug_22 svc:/system/timezone:default
# svcprop timezone:default |grep localtime timezone/localtime astring US/Eastern
2. To change the default timezone, use the svccfg and then refresh the service with the svcadm command. For example:
# svccfg -s timezone:default setprop timezone/localtime = astring: US/Mountain # svcadm refresh timezone:default
3. Alternatively, the default timezone can be changed with the zic command. This is a reasonable way to change the timezone; it will fail immediately when you try to change the timezone using a wrong value. If you use svccfg and may make an spelling error then you might not realize it and the command would still work. Example to modify timezone via zic:
# /usr/sbin/zic -l US/Mountain
4. Another way to modify the default timezone is to use “nlsadm set-timezone”. Example:
// 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 Jul 20 16:58:42 EDT 2016
Solaris 10 OS and below
1. The default timezone is set in the /etc/TIMEZONE configuration file (symbolically linked to /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 ...
2. To change the system timezone, edit the /etc/TIMEZONE file and change the value of the TZ variable. For Example:
3. You must reboot the system for timezone changes to take effect.
A list of valid timezone/localtime values can be found in the /usr/share/lib/zoneinfo directory
For e.g. ‘Europe/Berlin’ in directory /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
Similarly for other continents/countries:
Africa/ America/ Asia/ -- lines omitted --
Example to set/change the timezone (TZ) only for one particular command
The below commands sets the TZ=Europe/London only for one particular command
# TZ=Europe/London date Wed Jul 20 22:31:17 BST 2016
# TZ="US/Central" date Wed Jul 20 16:35:33 CDT 2016
# TZ="US/Central" date '+%Y-%m-%d %H:%M:%S' 2016-07-20 16:35:35
Set timezone (TZ) variable per User
The TZ variable can be set per User in .profile or .login. For e.g.
# vi ~/.profile TZ=Europe/London
Set timezone (TZ) variable per non-global-zone (NGZ)
Ever since Zones was introduced way back in Solaris 10, there has been a demand for the ability for Zones to set its own time. The default TIMEZONE in a native non-global zone can be selected the same way as for a global zone.
Additional info to set/adjust the (hardware) clock on Solaris system
Check the current date/time on system using UTC clock info
# date -u Wed Jul 20 21:54:52 GMT 2016
Example Setting Another Time and Date in Greenwich Mean Time
The following command sets the date to Thu Jul 21 10:15:00 GMT 2016
# date -u 072110152016 Thu Jul 21 10:15:00 GMT 2016
# date Thu Jul 21 11:16:46 BST 2016
# date -u Thu Jul 21 10:16:54 GMT 2016