strptime和strftime

strftime是将时间格式化。strptime是将字符串解析成时间,按照特定的方式解析

1. strftime

import time
print("local_time:", time.localtime())
print(time.strftime("%Y-%M-%d %H:%M:%d", time.localtime()))

2. strptime

import time
str_time = "2022#10#30"
print(time.strptime(str_time, "%Y#%m#%d")) // "#"自定义的分隔符

 

你可能感兴趣的:(python)