def utcnow(format="ts"):
''' returns time-aware utc datetime object or timestamp of current time/date
@Param: format - defaults to timestamp, provide "dt" for datetime obj '''
dt = datetime.now(tz=pytz.utc)
if format == "dt":
return dt
else: # timestamp includes millis down to 6th decimal place
ts = str(dt.timestamp())
return ts.replace('.', '')
# DEBUG
# print(utcnow())
# print(utcnow("dt"))
# TODO add methods for converting to client local timezone dynamically
评论列表
文章目录