1 个回答|434 次阅读
1、使用time.time()方法获取当前时间戳
2、使用time.localtime()方法格式化时间戳
Python time localtime() 函数类似gmtime(),作用是格式化时间戳为本地的时间。 如果sec参数未输入,则以当前时间为转换标准。
3、使用strftime()函数接收时间元组,并返回以可读字符串表示的当地时间。
strftime()方法语法:time.strftime(format[, t])
示例:
import time time = time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())) print(time)
输出结果如下:
2022-04-27 14:37:18
请先 登录 后评论