欢迎光临
我们一直在努力

九八云Python教程:python strftime获取当前时间

说明

1、通过strptime()函数,可以获得与单一日期相关的数据。

2、strftime()函数的第二个参数接受struct_time对象。将秒数转换为标准时间。如果没有参数,回到现在的时间。time.localtime()的作用是将格式时间戳作为当地时间,具有sec参数,即对应的time.time()函数的秒数,

实例

import time
 
s = time.strftime("%H:%M:%S", time.localtime())
print(s)

以上就是python strftime获取当前时间,希望对大家有所帮助。更多Python学习指路:九八云python教程

本文教程操作环境:windows7系统、Python 3.9.1,DELL G3电脑。

赞(0) 打赏
未经允许不得转载:九八云安全 » 九八云Python教程:python strftime获取当前时间

评论 抢沙发