Skip to main content

UTC

It Should Be Easier

The current Python landscape doesn’t make it simple enough to use timezone aware timestamps.

It’d be nice if datetime.datetime.now() gave you a timezone-aware datetime in your current timezone, but it doesn’t.

You’d expect datetime.datetime.utcnow() to at least be timezone-aware, right? No. There’s no tzinfo on the datetime you get back from that function.

The pytz package has comprehensive support for time zones, and if you need to do something complicated, you should use that. But you don’t always need to do something complicated. Sometimes you just want UTC.

This package provides syntactic sugar around simple UTC handling that I’ve rewritten in too many times in past projects.

Usage

There is a now() function that does the right thing:

>>> import utc
>>> utc.now()
datetime.datetime(2013, 8, 30, 16, 51, 50, 316963, tzinfo=<UTC>)

And a datetime constructor that is UTC by default:

>>> utc.datetime(1900, 1, 1, 13, 25)
datetime.datetime(1900, 1, 1, 13, 25, tzinfo=<UTC>)

And a time constructor too:

>>> utc.time(13, 26, 36)
datetime.time(13, 26, 36, tzinfo=<UTC>)

That is all.

Metadata

Release files for utc 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for utc 0.0.3
File Size Uploaded Provenance Actions
utc-0.0.3.tar.gz 1.9 kB Without provenance Details for utc-0.0.3.tar.gz

Release files / utc-0.0.3.tar.gz

Download URL utc-0.0.3.tar.gz
Size 1.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7b842c4bb063b3882443010019734bbd8810291b8d738f7aadfc9ae89b5a1b7e
BLAKE2b-256 checksum
How to use checksums
dace694c9ec0f060611abaf13cfca477efbd5619d3cb5e6c6e4b58eafe1497d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for utc 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page