python time.ctime(),转化日期为字符串
time.ctime()方法
python time模块ctime()方法,可以将一个以秒为单位的时间戳转化为字符串,比如:'Fri Mar 3 21:36:19 2023'。
语法
ctime(seconds) -> string
python源码对ctime()方法的介绍:
Convert a time in seconds since the Epoch to a string in local time.
This is equivalent to asctime(localtime(seconds)). When the time tuple is
not present, current time as returned by localtime() is used.
参数
参数 | 描述 |
---|---|
seconds | 可选参数,时间戳,指定某一个日期距格林威治零时的总秒数;如果没有参数,则默认使用当前的日期。 |
返回值
具有类似于'Fri Mar 3 21:36:19 2023'格式的日期字符串。
ctime()实例代码
>>> import time
>>> time.ctime()
'Fri Mar 3 21:36:19 2023'
>>> time.ctime(666)
'Thu Jan 1 08:11:06 1970'