Times

0.7 · deprecated · verified Wed Apr 15

Times is a small, minimalistic Python library for handling time conversions between universal time and arbitrary timezones. Version 0.7, the latest release, was rewritten to be implemented on top of the 'Arrow' library, providing a consistent interface while leveraging Arrow's capabilities. The project has not seen active development since around 2015.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to convert local times to universal (UTC) and vice-versa, using string inputs or datetime objects, and how to format times for presentation in a specific timezone.

import times
import datetime

# Example 1: Accepting local time and converting to universal time
# The second argument can be a pytz.timezone instance or a timezone string.
# If local_time already has timezone info, omit the source timezone argument.
local_time_str_naive = '2012-02-01 11:31:45'
universal_time = times.to_universal(local_time_str_naive, 'Europe/Amsterdam')
print(f"Local (naive) to Universal: {universal_time}")

# Example 2: Accepting datetime string with offset (auto-detects timezone)
universal_time_offset = times.to_universal('2012-02-03 11:59:03-0500')
print(f"String with offset to Universal: {universal_time_offset}")

# Example 3: Presenting universal time to a local timezone
# (using the universal_time from above)
formatted_local_time = times.format(universal_time, 'America/New_York', '%Y-%m-%d %H:%M:%S %Z%z')
print(f"Universal to formatted local: {formatted_local_time}")

# Example 4: Converting universal datetime to local representation (less recommended for direct formatting)
local_dt_obj = times.to_local(universal_time, 'Asia/Tokyo')
print(f"Universal to local datetime object: {local_dt_obj}")

view raw JSON →