如何在 Python 中以毫秒为单位创建日期时间?

问题描述:

我可以通过 在 Java 中创建一个类似的 Date 对象java.util.Date(毫秒).如何在 Python 中创建可比对象?

I can create a similar Date object in Java by java.util.Date(milliseconds). How do I create the comparable in Python?

分配一个 Date 对象并初始化它以表示自称为纪元"的标准基准时间(即格林威治标准时间 1970 年 1 月 1 日 00:00:00)以来的指定毫秒数.

Allocates a Date object and initializes it to represent the specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.

只需将其转换为时间戳

datetime.datetime.fromtimestamp(ms/1000.0)