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秒
'''
相关推荐
知识分享小能手16 分钟前
Flask入门学习教程,从入门到精通,Flask智能租房——前期准备 知识点详解(5)
python·学习·flask
Curvatureflight20 分钟前
【架构实战】生产级大模型 API 接入指南:流式响应(Streaming)异常处理与监控闭环
python·架构
smj2302_796826521 小时前
解决leetcode第3943题递增后的数对数量
数据结构·python·算法·leetcode
এ慕ོ冬℘゜1 小时前
JS 前端基础面试题
开发语言·前端·javascript
浩少7021 小时前
【无标题】
java·开发语言
deepin_sir1 小时前
06 Chroma_持久化与生产环境部署实战
python
nnsix2 小时前
C# 字符串 根据换行符分割
开发语言·c#
Vallelonga2 小时前
Rust Conversion 工具 trait AsRef AsMut
开发语言·rust
Vallelonga2 小时前
Rust 中的“解引用”和智能指针与 MutexGuard 等
开发语言·rust
小鱼仙官2 小时前
Windonws 视频存储,10s/不限时
开发语言·qt·音视频