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秒
'''
相关推荐
思茂信息37 分钟前
CST软件对Customer Success OPPO手机电源适配器EMC仿真
开发语言·嵌入式硬件·matlab·3d·智能手机·cst
缺点内向2 小时前
如何在 C# 中将 Excel 工作表拆分为多个窗格
开发语言·c#·.net·excel
少废话h3 小时前
解决Flink中ApacheCommonsCLI版本冲突
开发语言·python·pycharm
serve the people3 小时前
TensorFlow 图执行(tf.function)的 “非严格执行(Non-strict Execution)” 特性
人工智能·python·tensorflow
天命码喽c3 小时前
GraphRAG-2.7.0整合Milvus-2.5.1
开发语言·python·milvus·graphrag
后端小张3 小时前
【JAVA进阶】Spring Boot 核心知识点之自动配置:原理与实战
java·开发语言·spring boot·后端·spring·spring cloud·自动配置
吴佳浩5 小时前
LangChain 深入
人工智能·python·langchain
网安-轩逸8 小时前
回归测试原则:确保软件质量的基石
自动化测试·软件测试·python
Mr_Xuhhh8 小时前
YAML相关
开发语言·python
咖啡の猫8 小时前
Python中的变量与数据类型
开发语言·python