A Python module that converts timezones, sets time and calculates the number of seconds since the UNIX epoch.
Download the epoch.py file and then import it into your python project.
import pyepoch
How to use PyEpoch.
# Gets today's date.
today = pyepoch.today()
Returns today's date using datetime.datetime
# Gets today's date.
today = pyepoch.today()
>>> 2018, 11, 8, 11, 32, 59, 744692
Returns the number of seconds passed up to a specific date since the Unix epoch.
The function takes two parameters:
- A date: a datetime object
- A timezone: a timezone string, ex. 'US/Pacific'
# Gets today's date.
today = pyepoch.today()
# Seconds up to today since the Unix epoch.
today = pyepoch.epoch_sec(today, 'US/Pacific')
>>> 2018, 11, 8, 11, 32, 59, 744692-08:00
Returns a passed in time into another timezone (also passed in) and sets the hour/minute/second in the passed in date.
The function takes five parameters:
- A date: a datetime object to be converted.
- A timezone: a timezone string, ex. 'US/Pacific'
- Hour int
- Minute int
- Second int
# Gets today's date.
today = pyepoch.today()
# Midnight pacific time today.
today = pyepoch.timezone(today, 'US/Pacific', 0, 0, 0)
>>> 2018-11-08 08:00:00-08:00
You can download the 'example.py' file to see the functions in action.
GitHub: @Buscedv
Edvard Busck-Nielsen 2020