python入门之time模块和datetime模块
time模块
时间三种表示:时间戳(秒单位),struct_time(元组,可以分开调用),指定格式(格式化)
time.sleep() 等待5秒钟
time.time() 返回时间戳
time.ctime() 返回当前系统的字符串时间
time.ctime(time.time()) 将时间戳转换为字符串格式
time.gmtime(time.time()) 将时间转换为struct_time格式,元组格式(国外时间,与本地相差12小时,UTC时区)
>>>time.struct_time(tm_year=2019, tm_mon=3, tm_mday=4, tm_hour=7, tm_min=17, tm_sec=6, tm_wday=0, tm_yday=63, tm_isdst=0)<<<
print(help(x)) 查看调用struct_time格式的方法
time.localtime(time.time()) 转换为struct_time格式,显示的是本地时间,UTC+8时区
time.mktime(time.localtime()) 与localtime相反,转换为时间戳
time.strftime("%Y-%m-%d %H:%M:%S,time.gmtime()") 将struct_time格式转换为指定的字符串格式
time.strptime("2017-01-01","%Y-%m-%d") 将字符串格式转换为struct_time格式
datetime模块
c_time = datetime.datetime.now() 当前时间(1)
print(c_time.timetuple()) 返回struct_time格式(2)
print(c_time.replace()) 返回当前时间,加入参数,如replace(,,),则替换时间(3)
(1)datetime.datetime(2019, 3, 4, 15, 42, 14, 241116)
(2)time.struct_time(tm_year=2019, tm_mon=3, tm_mday=4, tm_hour=15, tm_min=41, tm_sec=14, tm_wday=0, tm_yday=63, tm_isdst=-1)
(3)2019-03-04 15:41:14.967399
datetime.datetime.strptime("21/11/06 16:30","%d/%m/%y %H:%M") 将字符串转换为日期
new_date = datetime.datetime.now() + datetime.timedelta(days=) 比现在加10天
days=- 比现在减10天
hours=- 比现在减10小时
seconds= 比现在加10秒
weeks= 比现在加一周
python入门之time模块和datetime模块的更多相关文章
- Python之路(第十六篇)xml模块、datetime模块
一.xml模块 xml是实现不同语言或程序之间进行数据交换的协议,跟json差不多,但json使用起来更简单, xml比较早,早期许多软件都是用xml,至今很多传统公司如金融行业的很多系统的接口还主要 ...
- (转)python time模块和datetime模块详解
python time模块和datetime模块详解 原文:http://www.cnblogs.com/tkqasn/p/6001134.html 一.time模块 time模块中时间表现的格式主要 ...
- python time模块 sys模块 collections模块 random模块 os模块 序列化 datetime模块
一 collections模块 collections模块在内置的数据类型,比如:int.str.list.dict等基础之上额外提供了几种数据类型. 参考博客 http://www.pythoner ...
- python中time模块和datetime模块
time模块和datetime模块 时间分为三种模式(time 模块) 时间戳 (time.time()) 格式化字符串 (time.strftime(%Y-%m-%d %H:%M:%S %p)) ...
- Time模块和datetime模块
Time模块和datetime模块 一. 调用 import time #调用time模块 二.使用方法 1.time.time 拿到时间戳.以Linux诞生年份1970年开始计算到程序执 ...
- python time模块和datetime模块详解
一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...
- python time模块和datetime模块
一.time模块 time模块中时间表现的格式主要有三种: a.timestamp时间戳,时间戳表示的是从1970年1月1日00:00:00开始按秒计算的偏移量 b.struct_time时间元组,共 ...
- python笔记7 logging模块 hashlib模块 异常处理 datetime模块 shutil模块 xml模块(了解)
logging模块 日志就是记录一些信息,方便查询或者辅助开发 记录文件,显示屏幕 低配日志, 只能写入文件或者屏幕输出 屏幕输出 import logging logging.debug('调试模式 ...
- Python 标准类库-日期类型之datetime模块
标准类库-日期类型之datetime模块 by:授客 QQ:1033553122 可用类型 3 实践出真知 4 timedelta对象 4 class datetime.timedelta(da ...
随机推荐
- nodejs 静态文件服务器
https://cnodejs.org/topic/4f16442ccae1f4aa27001071 http://blog.csdn.net/zhangxin09/article/details/8 ...
- 第四章——Lock的使用
本章主要是讲解:使用Lock对象也能实现同步效果,而且使用起来更方便. 主要掌握两个方面: ReentrantLock类的使用 ReenTrantReadWriteLock类的使用
- CCS V5 使用教程三:程序调试
官网教程 新建调试工程 输入以下源码: #include <stdio.h> #include <c6x.h> ]; void main(void) { unsigned ; ...
- wpf dataGrid 选中行 失去焦点时 的背景颜色的更改
关于 wpf dataGrid 选中行 失去焦点时 的背景颜色的更改.很简单的方式,在datagrid的resource中更改InactiveSelectionHighlightBrushKey属性的 ...
- DataTable列查询加排序
DataTable列查询加排序 DataRow[] drArray = dt.Select("ANLYCOM_ID='" + chSPrdtStblAnly.AnlyComId + ...
- 3、perl进阶
1.条件判断与循环结构(if (unless) while(until) for foreach next last redo) if (unless) 关系运算符: 数字关系运算符(>,& ...
- jquery选择器中的find和空格,children和>的区别、及父节点兄弟节点,还有判断是否存在的写法
一.find和空格,children和>及其它的区别 空格:$('parent childchild')表示获取parent下的所有的childchild节点(所有的子孙). 等效成 = ...
- es6基础系列五--数组的拓展
Array.from() 用于将两类对象转为真正的数组,类似数组对象和可遍历对象(包括数据结构Set和Map)转化为数组 格式:Array.from(arrayLike[, mapFn[, thisA ...
- IOS开发学习 碎片S
非常感谢提供一下内容的人和组织! 字符串编码:http://www.cnblogs.com/KevinYang/archive/2010/06/18/1760597.html Foundation框架 ...
- GoWeb开发_Iris框架讲解(三):路由功能处理方式
Context概念 Context是iris框架中的一个路由上下文对象,在iris框架中的源码路径定义为:{$goPath}\github.com\kataras\iris\context\conte ...