# 导入time模块
import time
2、打印时间戳-time.time()
# 导入time模块
import time
# 打印时间戳
print(time.time())
3、格式化时间戳为本地的时间-time.localtime()
# 导入time模块
import time
# 格式化时间戳为本地的时间
print(time.localtime(time.time()))
4、优化格式化化版本-time.strftime()
# 导入time模块
import time
# 优化格式化化版本
print(time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time())))
print(time.strftime('%Y%m%d%H%M%S',time.localtime(time.time())))
输出:20210210204155
5、time.strftime的参数
strftime(format[, tuple]) -> string
将指定的struct_time(默认为当前时间),根据指定的格式化字符串输出
python中时间日期格式化符号: