What was midnight yesterday as an epoch time?

前端 未结 7 1357
太阳男子
太阳男子 2020-12-09 03:08

I\'m trying to get my head around the datetime module. I know the time now as an epoch and the time an event last happened (as an epoch time). What I need to do is figure

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-09 03:43

    To get the specific timezone's midnight timestamp:

    from datetime import datetime
    import pytz
    
    TZ = "Asia/Shanghai"
    datetime.now(pytz.timezone(TZ)).replace(hour=0, minute=0, second=0, microsecond=0).timestamp()
    

提交回复
热议问题