Python datetime.tzname() Method

Beginner
6 min read
Updated: Nov 2026
3 examples
datetime method

Definition

tzname() returns the name of the time zone as a string by calling self.tzinfo.tzname(self). For a naive datetime it returns None.

For the built-in timezone class, the name is the one you passed to timezone(offset, name); without a name Python generates 'UTC' for zero or 'UTC+HH:MM' otherwise. strftime() uses the same value for %Z.

datetime.tzname() is an instance method of datetime.datetime: call it on an existing object with dot notation, such as moment.tzname(...). Import the class first, for example from datetime import datetime. The time class has a method with the same name.

Syntax

Call it with no arguments.

python
name = moment.tzname()
CallWhat it does
datetime(2024, 3, 15, tzinfo=timezone.utc).tzname()Returns 'UTC'.
datetime(2024, 3, 15, tzinfo=timezone(timedelta(hours=-8))).tzname()Returns 'UTC-08:00'.
datetime(2024, 3, 15, tzinfo=timezone(timedelta(hours=9), "JST")).tzname()Returns 'JST'.

The name is only a label for people; Python never uses it in calculations.

Method signatures
python
datetime.tzname()
time.tzname()
tzinfo.tzname(dt)           # implemented by tzinfo subclasses
# returns: str or None

Parameters

tzname() takes no parameters on datetime and time objects.

Return Value

Return ValueDescription
strThe zone name or abbreviation reported by the tzinfo.
NoneFor naive values, or a tzinfo that returns None.

Python Examples

Example 1 — Compare tzname() with %Z

Print the name and the %Z text for a naive value, UTC, an unnamed offset, and a named offset.

python
from datetime import datetime, timedelta, timezone

zones = [None, timezone.utc, timezone(timedelta(hours=-8)), timezone(timedelta(hours=9), "JST")]
for zone in zones:
    moment = datetime(2024, 3, 15, 10, 30, tzinfo=zone)
    print(repr(moment.tzname()), repr(moment.strftime("%Z")))

How It Works

  1. Naive. tzname() gives None, and %Z becomes an empty string.
  2. Generated names. Unnamed fixed offsets report UTC or UTC-08:00.
  3. Your own label. The second argument of timezone() becomes the name, here JST.

Example 2 — Label Converted Times with Their Zone Names

Convert one UTC event into two named offices and print the local time with the zone name.

python
from datetime import datetime, timedelta, timezone

offices = [timezone(timedelta(hours=1), "CET"), timezone(timedelta(hours=-8), "PST")]
event = datetime(2024, 11, 5, 18, 0, tzinfo=timezone.utc)

print(event.tzname())
for office in offices:
    local = event.astimezone(office)
    print(f"{local:%H:%M} {local.tzname()}")

How It Works

  1. Start in UTC. The event's own name is UTC.
  2. Name follows the zone. After astimezone(), each value reports the name of its new tzinfo.
  3. Readable output. Showing the name next to the time tells readers which clock it is.

Example 3 — Two Zones Can Share One Name

China and US Central both use the abbreviation CST, but their offsets are 14 hours apart.

python
from datetime import datetime, timedelta, timezone

china = timezone(timedelta(hours=8), "CST")
central = timezone(timedelta(hours=-6), "CST")
a = datetime(2024, 1, 15, 9, 0, tzinfo=china)
b = datetime(2024, 1, 15, 9, 0, tzinfo=central)

print(a.tzname() == b.tzname())
print(a == b)
print(b - a)

How It Works

  1. Same label. Both tzinfo objects report CST.
  2. Different instants. 09:00 at UTC+08:00 and 09:00 at UTC-06:00 are not the same moment.
  3. The gap. Subtracting gives 14 hours, the difference between the offsets; the name alone could never tell you that.

Frequently Asked Questions

Call moment.tzname(). It returns a str such as UTC, or None for naive values.
The timezone was created without a name. Pass one: timezone(timedelta(hours=5, minutes=30), "IST").
Yes for aware values. For naive values tzname() returns None and %Z gives an empty string.
Not reliably, because abbreviations such as CST and IST mean different zones. Store offsets or IANA names like Asia/Kolkata.
The abbreviation in effect at that moment, for example CET in winter and CEST in summer for Europe/Berlin.

Next: datetime.utcfromtimestamp()

Deprecated classmethod: timestamp to naive UTC datetime; use fromtimestamp(ts, tz=timezone.utc).

utcfromtimestamp() →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

13 people found this page helpful