import time
import datetime
'''
print(time.time()) #返回当前系统时间戳
print(time.ctime()) #返回当前系统时间
print(time.ctime(time.time()-86640)) #将时间戳转为字符串格式
print(time.gmtime(time.time()-86640)) #将时间戳转换成struct_time格式
print(time.localtime()) #将时间戳专程从struct_time格式,但返回的本地时间
print(time.mktime(time.localtime())) #与time.localtime()功能相反,将struct_time格式转回成时间戳格式
time.sleep(4) #程序睡眠4秒再执行
print("******")
print(time.strftime("%Y-%m-%d %H:%M:%S",time.localtime()))#将struct_time格式转成指定的字符串格式
print(time.strptime("2018-03-06 11:51","%Y-%m-%d %H:%M"))#将字符串格式转换成struct_time格式
'''
'''
# print(datetime.date.today())#输出格式 2018-03-06
# print(datetime.date.fromtimestamp(time.time()-866400))#2018-02-24将时间戳转为日期格式
# current_time = datetime.datetime.now()#
# print(current_time)#输出2018-03-06 14:31:38.781600
# print(current_time.timetuple())#返回struct_time格式
# print(current_time.replace(2017,3,6))#输出2017-03-06 14:53:06.932600,返回当前时间,但指定的值将被替换
# str_to_date = datetime.datetime.strptime("2018/3/6 14:56","%Y/%m/%d %H:%M")#将字符串转换为日期格式
# print(str_to_date)
'''
# new_date = datetime.datetime.now() + datetime.timedelta(days=10)#比现在增加10天
# new_date = datetime.datetime.now() + datetime.timedelta(days=-10)#比现在减少10天
# new_date = datetime.datetime.now() + datetime.timedelta(hours=-10)#比现在减少10小时
# new_date = datetime.datetime.now() + datetime.timedelta(seconds=120)#比现在增加120秒
# new_date = datetime.datetime.now() + datetime.timedelta(minutes=30)#比现在增加30分钟
# print(new_date)

  

python之时间处理time模块的更多相关文章

  1. python的时间处理-time模块

    time模块 时间的表示方法有三种: 时间戳:表示的是从1970年1月1日0点至今的秒数 格式化字符串表示:这种表示更习惯我们通常的读法,如2018-04-24 00:00:00 格式化元祖表示:是一 ...

  2. Python之时间:datetime模块

    datetime在time基础之上封装了一些方法.但是time是经常使用的,datetime中的功能,time都能实现 一.datetime的三个模块 datetime.date datetime.t ...

  3. Python之时间:time模块

    import time   对于时间,使用最频繁的模块 1.获取当前时间 (1)时间戳 time.time() 时间戳:从1970年1月1日0点开始到现在按秒计算的偏移量 (2)时间元组 time.l ...

  4. Python之时间和日期模块

    1.import time 先要导入时间模块 1)time.time()得到当前的时间,返回的是时间戳,表示自1970年1月1日起到程序运行时的秒数 import time print(time.ti ...

  5. Python之时间:calender模块(日历)

    import calendar 1.星期 (1)calendar.day_name 星期的全称 print calendar.day_name for i in calendar.day_name: ...

  6. Python日期时间Date/Time

    Python程序可以处理多种方式的日期和时间.日期格式之间的转换是一种常见计算机的杂活. Python的时间和日历模块,能帮助处理日期和时间. Tick是什么? 为时间间隔,以秒为单位的浮点数.从“新 ...

  7. python 统计时间,写日志

    python 统计时间使用time模块,写日志使用logging模块,这两个都是标准模板. 测试socket使用socket模块 # 统计时间 ---------------------- impor ...

  8. Python的时间模块小结(转自:不懂真人)

    import datetimeprint time.time() #时间戳 print time.localtime(time.time()) #时间元组 print time.strftime('% ...

  9. 【转载】Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码

    本文转载自脚本之家,源网址为:https://www.jb51.net/article/147429.htm 一.Python中日期时间模块datetime介绍 (一).datetime模块中包含如下 ...

随机推荐

  1. C 碎片七 指针

    一.地址和指针 程序在编译过程中,系统会根据变量类型分配一定长度的内存单元.内存区中的每个字节都有一个编号,该内存单元的初始编号就是变量的"地址/指针",该内存单元的长度就是变量的 ...

  2. C 碎片一 计算机知识

    一.计算机知识 1, 计算机组成及工作原理 计算机是硬件和软件的结合体.硬件由主机箱和外部设备组成,主机主要包括CPU.内存.主板.硬盘.光驱.各种扩展卡.连接线.电源等:外部设备包括鼠标.键盘等.软 ...

  3. hibernate课程 初探单表映射2-2 hibernate常用配置

    1 hibernate.cfg.xml常用配置: show_sql 控制台打印sql format_sql 控制台将sql排版 hbm2ddl.auto: create 删除表结构,重新建表并插值 u ...

  4. 用gethub下载ardupilot的最新源码

    1进入gethub的官方网站https://github.com/作者:恒久力行 QQ:624668529    在搜索框内输入ardupilot并点击搜索点回车       2会看到很多工程,选择那 ...

  5. Web前端开发的学习过程

    2018年 5月27日 开始在MDN上学习HTML/CSS/JavaScript.——6月18日 基本学完MDN的“学习Web开发”的HTML/CSS/JavaScript部分. 6月9日 开始在IF ...

  6. 淘宝H5移动端解决方案

    详细:http://www.w3cplus.com/mobile/lib-flexible-for-html5-layout.html ; (function(win, lib) { var doc ...

  7. 工作中遇到的有关echarts地图和百度地图的问题

    工作中遇到的有关echarts地图和百度地图的问题 *** 前言:在做项目中需要制作一个场景是左边是柱状图,右边是地图,地图上悬浮一个按钮可以切换echarts地图和百度地图.*** 功能: 在点击左 ...

  8. 解决perl: warning: Setting locale failed.

    在Ubuntu Server 12.04上执行apt-get install命令时,报如下warning   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 ...

  9. python 学习之FAQ:find 与 find_all 使用

      FAQ记录   1. 错误源码 错误源码如下 def fillUnivList(_html,_ulist): soup =BeautifulSoup(_html,'html.parser') fo ...

  10. badboy页面脚本发生错误,解决方案

    1.参考网址:https://jingyan.baidu.com/article/e9fb46e17537797520f76645.html?from=qqbrowser061108 本人亲自测试,方 ...