strftime()方法的格式化操作
格式化字符串---------------日期/时间------------值范围和实例
- %Y--------------------------年份---------------------0001~9999
- %m-------------------------月份---------------------01~12
- %B-------------------------月名----------------------January~December
- %b-------------------------月名缩写-----------------Jan~Dec
- %d-------------------------日期----------------------01~31
- %A------------------------星期-----------------------Monday~Sunday
- %a------------------------星期缩写-----------------Mon~Sun
- %H------------------------小时(24h制)-----------------------00~23
- %M------------------------分钟------------------------------------00~59
- %S-----------------------秒---------------------------------------00~59
- %x-----------------------日期-------------------------------------月/日/年
- %X----------------------时间-------------------------------------时:分:秒
题目描述
使用time库把系统的当前时间信息以格式“2021年03月11日10时04分11秒”输出
代码实现
import time#time是python提供的处理时间的标准库
t =time.localtime()#localtime()获取的是当前时间戳对应的struct_time对象
print(time.strftime("%Y年%m月%d日%H时%M分%S秒",t))#strftime()方法时间格式化最有效的方法,第一个参数是输出的格式,第二个参数是时间戳