python之时间处理time模块
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模块的更多相关文章
- python的时间处理-time模块
time模块 时间的表示方法有三种: 时间戳:表示的是从1970年1月1日0点至今的秒数 格式化字符串表示:这种表示更习惯我们通常的读法,如2018-04-24 00:00:00 格式化元祖表示:是一 ...
- Python之时间:datetime模块
datetime在time基础之上封装了一些方法.但是time是经常使用的,datetime中的功能,time都能实现 一.datetime的三个模块 datetime.date datetime.t ...
- Python之时间:time模块
import time 对于时间,使用最频繁的模块 1.获取当前时间 (1)时间戳 time.time() 时间戳:从1970年1月1日0点开始到现在按秒计算的偏移量 (2)时间元组 time.l ...
- Python之时间和日期模块
1.import time 先要导入时间模块 1)time.time()得到当前的时间,返回的是时间戳,表示自1970年1月1日起到程序运行时的秒数 import time print(time.ti ...
- Python之时间:calender模块(日历)
import calendar 1.星期 (1)calendar.day_name 星期的全称 print calendar.day_name for i in calendar.day_name: ...
- Python日期时间Date/Time
Python程序可以处理多种方式的日期和时间.日期格式之间的转换是一种常见计算机的杂活. Python的时间和日历模块,能帮助处理日期和时间. Tick是什么? 为时间间隔,以秒为单位的浮点数.从“新 ...
- python 统计时间,写日志
python 统计时间使用time模块,写日志使用logging模块,这两个都是标准模板. 测试socket使用socket模块 # 统计时间 ---------------------- impor ...
- Python的时间模块小结(转自:不懂真人)
import datetimeprint time.time() #时间戳 print time.localtime(time.time()) #时间元组 print time.strftime('% ...
- 【转载】Python日期时间模块datetime详解与Python 日期时间的比较,计算实例代码
本文转载自脚本之家,源网址为:https://www.jb51.net/article/147429.htm 一.Python中日期时间模块datetime介绍 (一).datetime模块中包含如下 ...
随机推荐
- python协程与异步协程
在前面几个博客中我们一一对应解决了消费者消费的速度跟不上生产者,浪费我们大量的时间去等待的问题,在这里,针对业务逻辑比较耗时间的问题,我们还有除了多进程之外更优的解决方式,那就是协程和异步协程.在引入 ...
- 认识与入门 MarkDown (转Te_Lee)
Markdown 是一种轻量级的「标记语言」,它的优点很多,目前也被越来越多的写作爱好者,撰稿者广泛使用.看到这里请不要被「标记」.「语言」所迷惑,Markdown 的语法十分简单.常用的标记符号也不 ...
- 学习《CSS选择器Level-4》不完全版
1 概述 1.1 前言 选择器是CSS的核心组件.本文依据W3C的Selectors Level 4规范,概括总结了Level1-Level4中绝大多数的选择器,并做了简单的语法说明及示例演示.希望对 ...
- 三、css 和 js 的装载与执行
一个网站在浏览器端是如何渲染的? 一.html 页面加载渲染的过程. 请求回来最先应该是HTML,从一个字节流转换成字符流,浏览器拿到字符流,然后浏览器端进行相应的词法分析成相应的token,然后不断 ...
- $(formName).data(“bootstrapValidator”).getFieldElements('fieldName'); 校验单个字段
问题也出自于业务系统后台,应该来说也比较常见吧 房产类型分为一抵和二抵,二抵的时候用户必须填写一抵债权金额,一抵的时候则不显示一抵债权金额也不校验,因为我所有的校验都是写在标签上,哪些必填直接写在标签 ...
- pure响应式布局
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- centos7 初体验
centos7 https://linux.cn/tag-RHCSA%7CRHCSA.html #/etc/sysconfig/network NETWORKING=yes GATEWAY=192.1 ...
- Python3基础12(collections、struct、itertools、chardet等的使用)
import struct import base64import itertoolsimport chardet from collections import namedtuple,default ...
- cms-数据库设计
业务相关的3张表 1.类型表: CREATE TABLE `t_arctype` (`id` int(11) NOT NULL AUTO_INCREMENT,//id`typeName` varcha ...
- 禁止windows自动更新后重新启动
运行gpedit.msc: 按照下图操作: 参考:http://www.xitongcheng.com/jiaocheng/win7_article_94.html