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秒
'''
相关推荐
m0_602857761 天前
如何提升SQL存储过程逻辑复用_封装通用存储过程函数
jvm·数据库·python
傻啦嘿哟1 天前
如何在 Python 中使用 colorama 库来给输出添加颜色
开发语言·python
forEverPlume1 天前
mysql如何实现高可用集群架构_基于MHA环境搭建与部署
jvm·数据库·python
geovindu1 天前
go: Visitor Pattern
开发语言·设计模式·golang·访问者模式
宣宣猪的小花园.1 天前
C语言重难点全解析:内存管理到位运算
c语言·开发语言·单片机
方安乐1 天前
python之向量、向量和、向量点积
开发语言·python·numpy
zh1570231 天前
JavaScript中WorkerThreads解决服务端计算瓶颈
jvm·数据库·python
小小小米粒1 天前
Collection单列集合、Map(Key - Value)双列集合,多继承实现。
java·开发语言·windows
蜡台1 天前
Python包管理工具pip完全指南-----2
linux·windows·python
Mr.朱鹏1 天前
【Python 进阶 | 第四篇】Psycopg3 + Flask 实现 PostgreSQL CRUD 全流程:从连接池到RESTful接口
python·postgresql·flask·virtualenv·fastapi·pip·tornado