Timezone Hopping with Pendulum: Seamlessly Manage Time across Different Timezones
Working with data that spans multiple timezones is a daily reality in global data science projects. Converting, comparing, and displaying timestamps across UTC, New York, London, Tokyo, and others used to be painful. Pendulum makes timezone hopping effortless, readable, and reliable — turning complex timezone logic into simple, one-line operations.
TL;DR — Pendulum Timezone Superpowers
.in_timezone(tz)→ instant conversionpendulum.parse(..., tz=...)→ parse directly into any timezonependulum.now(tz)→ current time in any zone- Beautiful, human-friendly API
1. Basic Timezone Conversion
import pendulum
# Parse once, then hop anywhere
dt = pendulum.parse("2026-03-19 14:30:00", tz="UTC")
print("UTC:", dt)
print("New York:", dt.in_timezone("America/New_York"))
print("London:", dt.in_timezone("Europe/London"))
print("Tokyo:", dt.in_timezone("Asia/Tokyo"))
2. Real-World Data Science Examples
import pandas as pd
import pendulum
# In practice: df = pd.read_csv("global_sales.csv") with order_time as text
df = pd.DataFrame({"order_time": ["2026-03-19 14:30:00", "2026-07-01 09:15:00"]})
# Convert all timestamps to multiple timezones
df["order_utc"] = df["order_time"].apply(lambda x: pendulum.parse(x, tz="UTC"))
# pandas stores the results as Timestamps, so wrap them again with pendulum.instance()
df["order_ny"] = df["order_utc"].apply(lambda x: pendulum.instance(x).in_timezone("America/New_York"))
df["order_london"] = df["order_utc"].apply(lambda x: pendulum.instance(x).in_timezone("Europe/London"))
# Local hour analysis
df["hour_ny"] = df["order_ny"].apply(lambda x: x.hour)
df["hour_london"] = df["order_london"].apply(lambda x: x.hour)
print(df[["order_time", "hour_ny", "hour_london"]])
3. Current Time in Any Timezone
# Current time anywhere in the world
now_ny = pendulum.now("America/New_York")
now_tokyo = pendulum.now("Asia/Tokyo")
now_utc = pendulum.now("UTC")
print(f"Right now in New York: {now_ny}")
print(f"Right now in Tokyo: {now_tokyo}")
4. Best Practices in 2026
- Always parse with an explicit
tzparameter - Store data internally in UTC and convert only for display or local analysis
- Use Pendulum’s
in_timezone()for clean, chainable conversions - Combine with pandas
.apply()for fast vectorized timezone hopping - Document the source timezone of any incoming data
What Happens When You Hop
in_timezone() (alias in_tz()) never changes the instant; it only changes how that instant is displayed. Two pendulum datetimes in different zones that describe the same moment compare equal. If you want to keep the wall-clock reading and attach a different zone — for example, a time typed by a user in Karachi but stored without a zone — create it with pendulum.datetime(..., tz="Asia/Karachi") or pendulum.parse(text, tz="Asia/Karachi") instead.
When pendulum objects go into a pandas column, pandas converts them to its own Timestamp type. The instant and zone are preserved, but pendulum-only methods such as in_timezone() disappear, which is why the example above wraps each value with pendulum.instance() again. For large DataFrames it is simpler and much faster to stay in pandas with dt.tz_localize() and dt.tz_convert(), and to use pendulum for individual values, configuration and display.
A good rule for global data is: store UTC, convert at the edges. Logs, databases and feature tables keep one consistent zone; reports and user interfaces convert to the reader's zone at the last moment.
Worked Example: A Meeting Across Offices
import pendulum
meeting = pendulum.datetime(2026, 3, 30, 15, 0, tz="Asia/Karachi")
offices = ["Europe/London", "America/New_York", "Asia/Tokyo"]
for zone in offices:
local = meeting.in_timezone(zone)
print(f"{zone:18} {local.format('ddd D MMM HH:mm')} (UTC{local.format('Z')})")
same = meeting.in_timezone("UTC")
print(same == meeting) # True - same instant
# Same wall clock in another zone is a different instant
relabelled = pendulum.datetime(2026, 3, 30, 15, 0, tz="Europe/London")
print(relabelled.diff(meeting).in_hours()) # 4
London has already moved to summer time by 30 March 2026, so the gap to Karachi is four hours rather than five; pendulum applies the rule automatically.
Common Mistakes
- Confusing conversion with relabelling:
in_timezone()converts - Hard-coding offsets between cities: they change with daylight saving
- Mixing pendulum objects into pandas columns for heavy work; pandas
tz_convertis vectorised
Quick Summary
in_timezone()keeps the instant and changes the display- Equal instants compare equal across zones
- Use pandas
dt.tz_convertfor large columns
Conclusion
Timezone hopping with Pendulum turns what used to be a headache into a pleasure. Its simple, readable API lets you parse, convert, and display times across any timezone with minimal code. In 2026 data science projects, Pendulum is the go-to library for handling global timestamps cleanly and correctly — saving you time, reducing bugs, and making your time-based analysis accurate and professional.
Next steps:
- Take any dataset with timestamps and add columns for key timezones using Pendulum’s
in_timezone()