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. Elasticsearch如何安装中文分词插件ik

    elasticsearch-analysis-ik 是一款中文的分词插件,支持自定义词库. 安装步骤: 1.到github网站下载源代码,网站地址为:https://github.com/medcl/ ...

  2. SpringMVC09 Converter变流器、数据回显、异常测试

    1.配置web.xml文件 <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3// ...

  3. POI 博客总结.....

    主键类: HSSFRow row1= sheet.createRow(1); row.createCell(0).setCellValue("学生编号"); row.createC ...

  4. SpringBoot2.0之三 优雅整合Spring Data JPA

      在我们的实际开发的过程中,无论多复杂的业务逻辑到达持久层都回归到了"增删改查"的基本操作,可能会存在关联多张表的复杂sql,但是对于单表的"增删改查"也是不 ...

  5. Android在应用设置里关闭权限,返回生命周期处理

    问题 在处理6.0运行时权限时,很多人都忽略了这样一个问题: 在一个App应用里,如果已经允许了一个权限比如(读取通讯权限),此刻去调用相机,弹出权限申请对话框,此刻点击拒绝,然后经过处理后弹出去设置 ...

  6. django Q条件

    #q条件from django.db.models import Qq = Q(name__startswith="p") | Q(name__startswith="l ...

  7. python使用浮点类型float计算后,数值不对_20180827

    在练习时,输入如下代码: 结果不准确. 原因:https://blog.csdn.net/bitcarmanlee/article/details/51179572 浮点数一个普遍的问题就是在计算机的 ...

  8. hdu-2255 奔小康赚大钱---KM模板

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2255 题目大意: Problem Description 传说在遥远的地方有一个非常富裕的村落,有一 ...

  9. 【转】CentOS 7.0 安装Redis 3.2.1详细过程和使用常见问题

    http://www.linuxidc.com/Linux/2016-09/135071.htm 环境:CentOS 7.0 Redis 3.2.1 Redis的安装与启动 这里我把Redis放在/h ...

  10. python3安装pip

    wget --no-check-certificate https://pypi.python.org/packages/source/p/pip/pip-8.0.2.tar.gz#md5=3a73c ...