DateTime::TimeZone::Local::Unix(3) User Contributed Perl Documentation DateTime::TimeZone::Local::Unix(3)

# [SYNOPSIS](#SYNOPSIS)

```
  my $tz = DateTime::TimeZone->new( name => 'local' );
  my $tz = DateTime::TimeZone::Local->TimeZone();
```

# [DESCRIPTION](#DESCRIPTION)

This module provides methods for determining the local time zone on a Unix platform.

# [HOW THE TIME ZONE IS DETERMINED](#HOW_THE_TIME_ZONE_IS_DETERMINED)

This class tries the following methods of determining the local time zone, in the order listed here:

- $ENV{TZ}
  
  It checks $ENV{TZ} for a valid time zone name.
- */etc/timezone*
  
  If this file exists, it is read and its contents are used as a time zone name.
  
  Note that this file may be out of date on many systems, as modern distros may not do a good job of updating this file. If you find that this file is not being updated, you may want to consider deleting it so that one of the following methods can be used.
- */etc/localtime*
  
  If this file is a symlink to an Olson database time zone file (usually in */usr/share/zoneinfo*) then it uses the target file's path name to determine the time zone name. For example, if the path is */usr/share/zoneinfo/America/Chicago*, the time zone is "America/Chicago".
  
  Some systems just copy the relevant file to */etc/localtime* instead of making a symlink. In this case, we look in */usr/share/zoneinfo* for a file that has the same size and content as */etc/localtime* to determine the local time zone.
- */etc/TIMEZONE*
  
  If this file exists, it is opened and we look for a line starting like "TZ = ...". If this is found, it should indicate a time zone name.
- */etc/sysconfig/clock*
  
  If this file exists, it is opened and we look for a line starting like "TIMEZONE = ..." or "ZONE = ...". If this is found, it should indicate a time zone name.
- */etc/default/init*
  
  If this file exists, it is opened and we look for a line starting like "TZ=...". If this is found, it should indicate a time zone name.

**Note:** Some systems such as virtual machine boxes may lack any of these files. You can confirm that this is case by running:

```
    $ ls -l /etc/localtime /etc/timezone /etc/TIMEZONE \
        /etc/sysconfig/clock /etc/default/init
```

If this is the case, then when checking for timezone handling you are likely to get an exception:

```
    $ perl -wle 'use DateTime; DateTime->now( time_zone => "local" )'
    Cannot determine local time zone
```

In that case, you should consult your system *man* pages for details on how to address that problem. In one such case reported to us, a FreeBSD virtual machine had been built without any of these files. The user was able to run the FreeBSD *tzsetup* utility. That installed */etc/localtime*, after which the above timezone diagnostic ran silently, *i.e.*, without throwing an exception.

2026-10-25 perl v5.44.0

---

Document: DateTime::TimeZone::Local::Unix(3pm) from perl-datetime-timezone 2.71-r1 (Chainguard OS)
Source: https://github.com/houseabsolute/DateTime-TimeZone
