python-time模块使用

python-time模块使用

1,两个时间概念
  1. struct_time: time模块的时间对象
  2. 时间戳:从1970年1月1日到现在的秒数,是一个正的浮点数。
2, 日常使用-获取当前时间并将时间按照自己的格式生成字符串

%字符代表变量

  1. %Y 年变量
  2. %m 月变量
  3. %d 日变量
  4. % H 小时变量
  5. %M 分钟变量
  6. %S 秒数变量
python 复制代码
import time

# 1. 获取当前时间, time.localtime()方法返回一个struct_time对象
current = time.localtime()

# 2, 将struct_time对象按照特定格式转换为字符串
# 使用方法:利用time.strftime(字符串格式,struct_time)
current_str = time.strftime('%Y年%m月%d日 %H时%M分%S秒', current)
print(current_str)
'''
2024年01月06日 21时33分05秒
'''
相关推荐
IT_Octopus6 小时前
JSON 日志里的 `{“$ref“:“$.xxx“}`:从 fastjson 兼容包到原生 fastjson2 的迁移实录
开发语言·python·json
geovindu6 小时前
python:HandWriting Recognition using paddlepaddle
开发语言·后端·python·paddlepaddle
wuyk5556 小时前
Python 零基础入门第九章:用户输入与 While 循环
开发语言·python
兮动人7 小时前
Python变量与常量
开发语言·python·机器学习·python变量与常量
风筝在晴天搁浅7 小时前
解题代码清爽版
java·开发语言
2601_962300817 小时前
机器学习的理想基石
人工智能·python·机器学习·编程语言·数据处理
Java后端的Ai之路7 小时前
21、Python - 命令模式
开发语言·人工智能·python·命令模式·外观模式
astronautyi7 小时前
Go 运行时内存分配与 GC 位图深度剖析
开发语言·后端·golang
2601_962077987 小时前
机器学习及其Python实践
pytorch·python·机器学习·tensorflow·scikit-learn
techdashen7 小时前
Go 中如何处理错误
开发语言·后端·golang