首页 > 解决方案 > 在python中以毫秒为单位获取GMT时间

问题描述

试图在 Python 中以毫秒为单位获得 GMT,我可以在 Java 中实现它,但需要 python 帮助。爪哇版:

Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
long time = cal.getTimeInMillis();
Sample output - 1528893731677

蟒蛇版本:

millis = int(round(time.time() * 1000)) // How to get GMT time here?
Sample output - 1528953926983

标签: javapythonpython-3.x

解决方案


from datetime import datetime
print(datetime.utcnow().timestamp() * 1000)

推荐阅读