mirror of
https://github.com/tencentmusic/cube-studio.git
synced 2024-12-21 06:19:31 +08:00
19 lines
399 B
Python
19 lines
399 B
Python
|
|
from datetime import datetime
|
|
|
|
import pytz
|
|
|
|
EPOCH = datetime(1970, 1, 1)
|
|
|
|
|
|
def datetime_to_epoch(dttm):
|
|
if dttm.tzinfo:
|
|
dttm = dttm.replace(tzinfo=pytz.utc)
|
|
epoch_with_tz = pytz.utc.localize(EPOCH)
|
|
return (dttm - epoch_with_tz).total_seconds() * 1000
|
|
return (dttm - EPOCH).total_seconds() * 1000
|
|
|
|
|
|
def now_as_float():
|
|
return datetime_to_epoch(datetime.utcnow())
|