首页 > 其他分享 >时间模块time-常用方法

时间模块time-常用方法

时间:2022-08-13 23:00:46浏览次数:58  
标签:常用 元组 tm 时间 模块 time 字符串 localtime

时间戳

# 获取时间戳
time.time()

# 时间元组转为时间戳
time.mktime(time.localtime())

时间元组

# 获取时间元组
time.localtime()
# time.struct_time(
	# 年月日
	# tm_year=2022, tm_mon=8, tm_mday=13, 
	# 时分秒
	# tm_hour=21, tm_min=48, tm_sec=54, 
	# 本周第几天(周日是第0天),本年第几天
	# tm_wday=5, tm_yday=225, tm_isdst=-1
	# )

# 时间戳转为时间元组
time.localtime(time.time())
# 时间格式的字符串转时间元组
time.strptime("2022-08-13 21:38:5", "%Y%m%d %H:%M:%S")

字符串

# 时间元组转字符串
time.strftime("%Y%m%d %H:%M:%S", time.localtime())

# 格式化输出时间
time.strftime("%Y-%m-%d")

总结

image

标签:常用,元组,tm,时间,模块,time,字符串,localtime
From: https://www.cnblogs.com/gao-ch/p/16584474.html

相关文章

  • 常用Dos命令
    常用的Dos命令#盘符切换例:D:+enter#查看当前目录下的所有目录dir#切换目录cd(即changedirectory)进入xxx(如下级目录)cd/dxxx(如D:\software)可直接跨盘进......
  • C++ timed_mutex
    #include<iostream>#include<thread>#include<mutex>std::timed_mutexmutex;voidmythread(){std::chrono::millisecondstimeout(100);//100msstd......
  • [JAVA]eclipse常用快捷键
    ①alt+/   (代码自动补全)    main然后alt+/补全main方法    syso然后alt+/补全输出语句②选中一行后ctrl+/     (对单行......
  • TimescaleDB 时间序列预测
    TimescaleDB与PostgreSQL协同使用,在我们使用时间序列数据时,时间序列数据的预测也是一个主要应用。在tutorial:Time-SeriesForecasting实验教程中,我们仍然利用nyc_data......
  • 使用 TimescaleDB + Prometheus + Grafana 实现指标数据采集、存储及可视化
    目录0.Background1.设置Timescalepg_prometheus和postgresql适配器1.1安装pg_prometheus1.2创建Prometheus数据库1.3安装prometheus-postgresql-adapter1.4导入......
  • TimescaleDB 实现 Prometheus 远程存储
    目录1.为什么要将TimescaleDB与Prometheus结合使用2.如何在Prometheus中使用TimescaleDB3.搭建环境3.1安装pg_prometheus3.2创建Prometheus数据库3.3安装prometheu......
  • cmd下执行pytest报错找不到文件模块
     现象:ModuleNotFoundError:Nomodulenamed'common'  解决方案:文件开头加入代码importos,syssys.path.append(os.getcwd())如果你对自己没有观察,对自己没有觉......
  • 物联网赛程各模块笔记目录
    ReadMeWelcometomyblog!【物联网网络搭建与配置】Visio绘图【物联网网络搭建与配置】物联网基础知识总结【物联网平台运行维护】数据库系统维护总结【物联网平台运......