I wonder if there's any way to get the UNIX timestamp at the beginning of a certain day, i.e the midnight timestamp of each day given its timezone.
Preferably without relying on other pip modules.
I wonder if there's any way to get the UNIX timestamp at the beginning of a certain day, i.e the midnight timestamp of each day given its timezone.
Preferably without relying on other pip modules.
Assuming you do not care about daylight savings time and you know the UTC offset which was in effect at that time (as opposed to the UTC offset which is in effect now), you can just do this:
import datetime as dt
return dt.datetime(year, month, day, tzinfo=dt.timezone(utc_offset)).timestamp()
The hour, minute, and second default to zero, so you can skip them. The timezone
class does not handle daylight savings time, historical changes in timezone definitions (e.g. British Double Summer Time), or any other temporal anomalies (e.g. there was no December 30, 2011 in Samoa); it is a "dumb" offset. It is equivalent (in this case) to adding or subtracting the offset directly onto the timestamp and then working in UTC. You must ensure this is correct for your use case. If you need better timekeeping, you should install and make use of pytz.