• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to Set the TimeZone in Solaris 10,11

by admin

The Ask

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:

TZ=US/Eastern

3. You must reboot the system for timezone changes to take effect.

NOTE: The tzreload command, which is available in Solaris 10 Update 9 (and above), doesn’t eliminate the need to reboot when the TZ variable is modified.

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

Filed Under: Solaris, Solaris 11, Zones

Some more articles you might also be interested in …

  1. Active FTP vs. Passive FTP
  2. Solaris 11.2 : Adding new resources to a running zone online
  3. Managing network resources in Solaris 11 using “dlstat” and “flowstat”
  4. How to allow only specific non-root user(s) to use crontab
  5. Oracle Solaris 11 Package Naming scheme ( version format )
  6. The ultimate Solaris sendmail troubleshooting guide
  7. Solaris Interview Questions – Inodes and the Filesystem Troubleshooting
  8. How to log SSH login attempts to a file in Solaris
  9. How to disable IPv6 in Solaris 11
  10. Solaris ZFS : How to replace a failed disk in rpool (x86)

You May Also Like

Primary Sidebar

Recent Posts

  • JavaFX ComboBox: Set a value to the combo box
  • Nginx load balancing
  • nginx 504 gateway time-out
  • Images preview with ngx_http_image_filter_module

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright