Skip to main content

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


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 hashes)

Uploaded Source

Built Distribution

sometime-1.2.2-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page