Provides methods to manipulate and format various time-based objects into human-readable strings.
Project description
Time Formatting Tools
Provides methods to manipulate and format various time-based objects into human-readable strings in Python.
Usage
import datetime
import timefmt
now = datetime.datetime.now()
print("Now (short):", timefmt.dt.short(now))
print("Now (long):", timefmt.dt.long(now))
since_epoch = datetime.timedelta(seconds=now.timestamp())
print("Time since Jan. 1st, 1970 (short):", timefmt.td.short(since_epoch))
print("Time since Jan. 1st, 1970 (long):", timefmt.td.long(since_epoch))
# You can also automatically detect which type it is, like so
import random
random_choice = random.choice([now, since_epoch])
print("Unknown time format value (short):", timefmt.auto(random_choice))
print("Unknown time format value (long):", timefmt.auto(random_choice, long=True))
This prints the following:
Now (short): 11:12:12 AM
Now (long): 11:12:12 AM US Mountain Standard Time
Time since Jan. 1st, 1970 (short): 2817W 2D 18:12:12
Time since Jan. 1st, 1970 (long): 2817 weeks, 2 days, 18 hours, 12 minutes, and 12 seconds
Unknown time format value (short): 11:12:12 AM
Unknown time format value (long): 11:12:12 AM US Mountain Standard Time
Full Documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
timefmt-0.2.3.tar.gz
(16.1 kB
view details)
Built Distribution
timefmt-0.2.3-py3-none-any.whl
(17.5 kB
view details)
File details
Details for the file timefmt-0.2.3.tar.gz
.
File metadata
- Download URL: timefmt-0.2.3.tar.gz
- Upload date:
- Size: 16.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f046d8349f1f578d5f3408fb5bc7c0da0524cd51ab9d7158fa046d83a22bd965 |
|
MD5 | 515b0b05217fc9916486c8077c825167 |
|
BLAKE2b-256 | 2a62aceb8f7c45c25b6279f4437a3ecf3d153ab368faf95799147b7e498496d0 |
File details
Details for the file timefmt-0.2.3-py3-none-any.whl
.
File metadata
- Download URL: timefmt-0.2.3-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e04d371a0ac215cfde8966916d2e509e9d9c33c6c4a5445a8267eeb3c218aa38 |
|
MD5 | 08a0c3d896604308264416664a80926f |
|
BLAKE2b-256 | 2d76f745dd54d532ac3efff82e038ae9e50240587d5c4cea26f582093ceb4f05 |