Get timestamp, formatted date, and perform date/time operations.
Project description
sometime
Get timestamp, formatted date, and perform date/time operations.
Official Release
Sometime v1.2.0
pip install sometime -U
Basic Usage
from sometime import Sometime
# Default initialization
ts = Sometime()
# Custom initialization
ts = Sometime(1650614778, utc=True)
# Set timestamp in seconds
ts.timestamp(seconds)
ts["timestamp"] = seconds
# Set date/time based on date/time string
# https://help.gnome.org/users/gthumb/stable/gthumb-date-formats.html.en"
ts.from_iso("2022-04-22", "%Y-%m-%d")
print("Timestamp:", ts.timestamp())
Get Unix Timestamp
print("Timestamp:", ts.timestamp())
Get current Unix Timestamp
print("Current Timestamp:", ts.now())
Add or subtract years
ts = Sometime(seconds)
ts.year(years=-25)
ts.year(years=100)
print("Year:", ts.year())
print("Year:", ts["%Y"])
Get name of the month
ts = Sometime(seconds)
ts.name_of_month()
print("Date of the Month:", ts.name_of_month())
Add or subtract months
ts = Sometime(seconds)
ts.month(months=-1)
ts.month(months=12)
print("Month:", ts.month())
Add or subtract days
ts = Sometime(seconds)
ts.day(days=-7)
ts.day(days=14)
print("Day:", ts.day())
Add or subtract hours
ts = Sometime(seconds)
ts.hour(hours=-8)
ts.hour(hours=24)
hour = ts.hour()
print("Hour:", ts.hour())
Add or subtract minutes
ts = Sometime(seconds)
ts.minute(minutes=-5)
ts.minute(minutes=30)
minute = ts.minute()
print("Minute:", ts.minute())
Add or subtract seconds
ts = Sometime(seconds)
ts.second(seconds=-1)
ts.second(seconds=30)
second = ts.second()
print("Second:", ts.second())
Get if AM/PM
ts = Sometime(seconds)
ts.period()
print("Period:", ts.period())
Get the Day of the Week
ts = Sometime(seconds)
print("Day of the Week:", ts.day_of_week())
Add or subtract to date/time
ts = Sometime(seconds)
print("Timestamp:", ts.timestamp())
ts.add(years=1, months=2, days=3, hours=4, minutes=5, seconds=6)
print("Timestamp:", ts.timestamp())
Format date/time into string representation
ts = Sometime(seconds)
print("Timestamp:", ts.custom("%Y-%m-%d %H:%M:%S %p"))
Get yesterday's on custom formatting
ts = Sometime(seconds)
print("Yesterday:", ts.yesterday("%Y-%m-%d %H:%M:%S %p"))
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
sometime-1.2.2.tar.gz
(3.4 kB
view details)
Built Distribution
File details
Details for the file sometime-1.2.2.tar.gz
.
File metadata
- Download URL: sometime-1.2.2.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52e3869ca3aa31e1566e65058992bd8cca66fd3cb416f052b6761acea6b0fc15 |
|
MD5 | 657efc8b3067f8ed305cc11ccd80de82 |
|
BLAKE2b-256 | 933c49f636b7856cf2d90c429e5d838f64feaa609e4cf4a9f5b8edf71674ddbc |
File details
Details for the file sometime-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: sometime-1.2.2-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.11.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f6a19431b62df6c7320fe01589571a96e86c95f9073e508c17d0bf759b9797e6 |
|
MD5 | 6b8a5f4fc467ca3b676ec8c21906c53b |
|
BLAKE2b-256 | 76eeb0c9cefe512190caecd99aab9296cb337670b604ea670f8bbeb21896bd98 |