Python datetime.timetz() Method

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

Definition

moment.timetz() returns a time object with the hour, minute, second, microsecond, and the same tzinfo as the datetime. For an aware datetime, the result is an aware time.

It is the zone-keeping twin of time(). Passing the result to combine() with another date rebuilds an aware datetime in the same zone.

datetime.timetz() is an instance method of datetime.datetime: call it on an existing object with dot notation, such as moment.timetz(...). Import the class first, for example from datetime import datetime.

Syntax

Call it with no arguments on a datetime.

python
clock = moment.timetz()
CallWhat it does
datetime(2024, 2, 10, 7, 15, tzinfo=timezone.utc).timetz()Returns datetime.time(7, 15, tzinfo=datetime.timezone.utc).
datetime(2024, 2, 10, 7, 15).timetz()Returns datetime.time(7, 15): naive in, naive out.
datetime(2024, 2, 10, 7, 15, tzinfo=timezone.utc).timetz().utcoffset()Returns datetime.timedelta(0).

No conversion happens: the clock reading stays the same, only the zone travels with it.

Method signatures
python
datetime.timetz()
# returns: time(hour, minute, second, microsecond, tzinfo, fold=fold)

Parameters

timetz() takes no parameters.

Return Value

Return ValueDescription
timeThe clock fields together with the datetime's tzinfo (which may be None).

Python Examples

Example 1 — Keep the Zone with the Clock Time

Extract an aware time from a datetime in a named fixed zone and ask it for its name and offset.

python
from datetime import datetime, timedelta, timezone

berlin_winter = timezone(timedelta(hours=1), "CET")
moment = datetime(2024, 2, 10, 7, 15, tzinfo=berlin_winter)

clock = moment.timetz()
print(clock)
print(clock.tzname())
print(clock.utcoffset())

How It Works

  1. Offset printed. An aware time prints its offset after the clock, here +01:00.
  2. Name travels too. The time has the same tzinfo object, so tzname() still says CET.
  3. Offset as timedelta. utcoffset() on the time returns one hour.

Example 2 — Compare Aware Times from Different Zones

13:00 UTC and 18:30 at UTC+05:30 are the same moment of the day, so the aware times compare equal.

python
from datetime import datetime, timedelta, timezone

ist = timezone(timedelta(hours=5, minutes=30))
utc_open = datetime(2024, 6, 1, 13, 0, tzinfo=timezone.utc).timetz()
ist_open = datetime(2024, 6, 1, 18, 30, tzinfo=ist).timetz()
print(utc_open, ist_open)
print(utc_open == ist_open)
print(utc_open.replace(tzinfo=None) == ist_open.replace(tzinfo=None))

How It Works

  1. Different readings. The two times show 13:00 and 18:30 with their own offsets.
  2. Offsets subtracted. Aware times are compared after removing the offset, and both mean 13:00 UTC.
  3. Naive comparison. Dropping the zones with replace() leaves 13:00 vs 18:30, which are not equal.

Example 3 — Rebuild an Aware datetime on Another Day

Reuse the aware clock time of one datetime to make the same alarm on the next day.

python
from datetime import date, datetime, timedelta, timezone

source = datetime(2024, 3, 15, 22, 0, tzinfo=timezone(timedelta(hours=-7)))
alarm = source.timetz()
next_day = datetime.combine(date(2024, 3, 16), alarm)
print(next_day)
print(next_day - source)
print(datetime.combine(date(2024, 3, 16), source.time()).tzinfo)

How It Works

  1. Zone carried over. combine() copies the time's tzinfo, so the new datetime is aware at UTC-07:00.
  2. Exactly one day. Subtracting the two aware values gives a timedelta of 1 day.
  3. time() loses it. Combining with the naive time() result gives a naive datetime, so tzinfo is None.

Frequently Asked Questions

Both return the clock part. time() drops the tzinfo; timetz() keeps it.
Python subtracts each utcoffset() first, so 13:00+00:00 equals 18:30+05:30.
Not reliably, because a time has no date. The tzinfo receives None and must return a fixed answer.
Use clock.replace(tzinfo=timezone.utc).
datetime.combine(some_date, aware_time) keeps the zone automatically.

Next: date.today()

Classmethod: the current local date (date.today) or naive local date and time.

today() →

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.

9 people found this page helpful