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.
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.1.tar.gz
(15.6 kB
view hashes)
Built Distribution
Close
Hashes for timefmt-0.2.1-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 388dec7d173b7a815593ac24f5a8ea0f8dd921bab11be79af2b77276c1a22845 |
|
MD5 | 0231eda3094eeba7c1ad9911a8999581 |
|
BLAKE2b-256 | 8a51350154c13ad3815853c3fc3844dc1642d51b5f18c08b3561867c990a9ebb |