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 小时前
Rust 学习(4)-函数与注释
开发语言·学习·rust
tiana_16 小时前
写了个零依赖的 Go 版本管理器,curl | bash 完事
开发语言·golang·bash
嘘嘘出差16 小时前
Python 爬虫入门实战:爬取豆瓣电影 Top 250
开发语言·爬虫·python
爱写代码的倒霉蛋16 小时前
实现协程的三种方式
开发语言·python
崖边看雾17 小时前
记录Python学习——第一章环境安装下载(Windows)
windows·python·学习·pycharm
CS创新实验室17 小时前
NumPy数组的C风格和Fortran风格
c语言·开发语言·numpy
用户2986985301417 小时前
Python 实现 Excel 到 ODS、XPS、PostScript 及 PDF/A-1b 的格式转换
后端·python·excel
本地化文档17 小时前
xlwings-docs-l10n
python·github·excel·gitcode·sphinx
逝水无殇17 小时前
C# 正则表达式详解
开发语言·后端·正则表达式·c#
朱永博18 小时前
使用Onnruntime实现Padim/Patchcore推理
开发语言·c#