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秒
'''
相关推荐
Blossom.1187 分钟前
Prompt工程与思维链优化实战:从零构建动态Few-Shot与CoT推理引擎
人工智能·分布式·python·智能手机·django·prompt·边缘计算
云栖梦泽17 分钟前
鸿蒙应用AI赋能与国际化落地实战:让待办应用跨越语言与智能边界
开发语言·鸿蒙系统
CoderCodingNo38 分钟前
【GESP】C++五级真题(结构体排序考点) luogu-B3968 [GESP202403 五级] 成绩排序
开发语言·c++·算法
想做后端的小C1 小时前
Java:接口回调
java·开发语言·接口回调
love530love2 小时前
Windows 11 下 Z-Image-Turbo 完整部署与 Flash Attention 2.8.3 本地编译复盘
人工智能·windows·python·aigc·flash-attn·z-image·cuda加速
麒qiqi2 小时前
理解 Linux IO 多路复用
开发语言·数据库
MediaTea2 小时前
Python:模块 __dict__ 详解
开发语言·前端·数据库·python
jarreyer2 小时前
python,numpy,pandas和matplotlib版本对应关系
python·numpy·pandas
代码or搬砖3 小时前
HashMap源码
开发语言·python·哈希算法
星辰_mya3 小时前
reids哨兵集群与选主
java·开发语言