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秒
'''
相关推荐
星落梦生2 小时前
SpringAOP基础笔记(7)
java·开发语言
曹牧4 小时前
Java:“刷新雪崩”
java·开发语言
郝学胜-神的一滴4 小时前
Effective STL 条款03:容器中的对象复制要廉价且正确
开发语言·数据结构·c++·算法·rpc·stl
西西弗Sisyphus5 小时前
C++ explicit 关键字工程实践
开发语言·c++
学无止境小袁同学6 小时前
Google ADK 学习指南
python·llm·agent·多agent·google adk·llmagent·agent cli
郝学胜-神的一滴6 小时前
Effective Python 条款35:用类封装替代生成器异常注入
开发语言·人工智能·python·金融·pandas·scikit-learn·matplotlib
feixing_fx7 小时前
原始类型与引用类型:赋值时到底复制了什么
开发语言·前端·javascript·前端框架
LK_077 小时前
【力扣】142. 环形链表 II |Python
python·leetcode·链表
wuyk5557 小时前
Python办公自动化-第02讲-Excel文件认知与四大库选型
开发语言·python·excel