如何在几毫秒内在Python中创建datetime? [英] How do I create a datetime in Python from milliseconds?

查看:106
本文介绍了如何在几毫秒内在Python中创建datetime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过在Java中创建类似的Date对象java.util.Date(milliseconds)。如何在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 GMT。

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)

这篇关于如何在几毫秒内在Python中创建datetime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆