'TimeStamp to Epoch Conversion in Python

How can I convert datetime variable to epoch ?

midnight = datetime.combine(datetime.today(), datetime.min.time())

yesterday_midnight = midnight - timedelta(days=1)

epocConv=yesterday_midnight.timestamp() * 1000

Above code, yesterday_might result in 2022-03-16 00:00:00 and epocConv result in 1647369000000.0

But I need yesterday-midnight to result 2022-03-16 12:00:00 AM and epocConv as 1647388800000



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source