python 时间感觉能用到的
datetime, string, timestamp 互转
import time
import datetime print datetime.datetime.now()
print datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') # datetime into string
print datetime.datetime.strptime("2017-03-02 20:17:05", '%Y-%m-%d %H:%M:%S') # string into datetime
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(1488457347.51)) # timestamp to string
print date.fromtimestamp(time.time())
date
import date
from datetime import date, timedelta #今天的日期(yyyy-MM-dd)
now = date.today()
#本月7号
seven_day = now.replace(day=7)
# 7号和今天的时间间隔(5days, 0:00:00)
delta = seven_day - now #date 加时间间隔
print now + delta
# 'get the seven days after today'
for i in range(0, 9):
print now + timedelta(days=i)
now = datetime.datetime(2017, 1, 1, 0, 0, 0)
for i in range(9):
print (now + timedelta(days=1)).strftime('%Y-%m-%d %H:%M:%S')
print date(2017, 2, 1) - date(2017, 1, 1)
print date(2017, 3, 1) - date(2017, 2, 1) #python 不能用timedelta在月上加1,可以这么获取下个月的今天
dt = date.today()
print date(dt.year, dt.month + 1, dt.day) print "*" * 100, 'time'
tm = datetime.time(23, 30, 0)
print tm
print tm.hour, tm.minute, tm.second, tm.microsecond
python 时间感觉能用到的的更多相关文章
- 浅谈Python时间模块
浅谈Python时间模块 今天简单总结了一下Python处理时间和日期方面的模块,主要就是datetime.time.calendar三个模块的使用.希望这篇文章对于学习Python的朋友们有所帮助 ...
- python时间处理之datetime
python时间处理之datetime 标签: pythondateimportstringc 2012-09-12 23:21 20910人阅读 评论(0) 收藏 举报 分类: Python系列( ...
- python 时间字符串与日期转化
python 时间字符串与日期转化 datetime.datetime.strptime(string, format) 根据指定的格式解析字符串为一个datetime类型.相当于datetime.d ...
- python时间日期字符串各种
python时间日期字符串各种 第一种 字符串转换成各种日期 time 库 # -*- coding: utf-8 -*- import time, datetime # 字符类型的时间 tss1 = ...
- Python 时间日历类型
# 时间日历 # time模块 # 提供了处理时间和表示之间转换的功能 # 获取当前时间戳 # 概念 # 从0时区的1970年1月1日0时0分0秒, 到所给定日期时间的秒数 # 浮点数 # 获取方式 ...
- Python时间与日期操作(datetime、time、calendar)
相关模块 模块 说明 time time是一个仅包含与日期和时间相关的函数和常量的模块,在本模块中定义了C/C++编写的几个类.例如,struct_time类 datetime datetime是一个 ...
- [python] 时间序列分析之ARIMA
1 时间序列与时间序列分析 在生产和科学研究中,对某一个或者一组变量 进行观察测量,将在一系列时刻 所得到的离散数字组成的序列集合,称之为时间序列. 时间序列分析是根据系统观察得到的时间序列数据, ...
- python—时间与时间戳之间的转换
python-时间与时间戳之间的转换 对于时间数据,如2016-05-05 20:28:54,有时需要与时间戳进行相互的运算,此时就需要对两种形式进行转换,在Python中,转换时需要用到time模块 ...
- python时间序列分析
题记:毕业一年多天天coding,好久没写paper了.在这动荡的日子里,也希望写点东西让自己静一静.恰好前段时间用python做了一点时间序列方面的东西,有一丁点心得体会想和大家 ...
随机推荐
- 编辑mac系统环境变量后保存,提示没有权限用到下面这个命令
编辑的文件是vim /etc/paths :w !sudo tee % %代表当前编辑文件名 MAC:查看端口占用情况: lsof -i tcp: list open files lsof -i 用以 ...
- smali文件内容具体介绍
大家都应该知道APK文件其实就是一个MIME为ZIP的压缩包,我们修改ZIP后缀名方式可以看到内部的文件结构,例如修改后缀后用RAR打开鳄鱼小顽皮APK能看到的是(Google Play下载的完整版版 ...
- kernel BUG
https://kernelnewbies.org/FAQ/BUG BUG() and BUG_ON(condition) are used as a debugging help when some ...
- angularjs中的$q
先说说什么是Promise,什么是$q吧.Promise是一种异步处理模式,有很多的实现方式,比如著名的Kris Kwal's Q还有JQuery的Deffered. 什么是Promise 以前了解过 ...
- centos7 配置ssh 免密码登陆
我只有一台机器,是因为要配置hadoop分布式环境用,需要配置ssh 两个用户: zhangxs, root 首先在切换到zhangxs用户下 执行[ ssh-keygen -t rsa] [zhan ...
- udp广播和多播
使用UDP协议进行信息的传输之前不需要建立链接, 客户端向服务器发送信息时,客户端只需要给出服务器的ip地址和端口号,可以发送信息.至于服务器端是否存在,是否能够收到该报文,客户端根本不用管. 广播( ...
- linux下tomcat6无法显示图片验证码 少了图形插件
linux下tomcat6无法显示图片验证码(windows下显示正常) 原创 2015年10月20日 10:31:47 3526 linux下tomcat6无法显示图片验证码(windows下显示正 ...
- prometheus监控方案
简介 prometheus 是一个开源的系统监控和告警的工具包,其采用pull方式采集时间序列,通过http协议传输. 架构 每个应用都通过javaagent向外提供一个http服务暴露出自己的JMX ...
- CentOS VSCode调试go语言出现:exec: "gcc": executable file not found in PATH
CentOS VSCode调试go语言出现:exec: "gcc": executable file not found in PATH 解决方案: 执行如下命令安装GCC,然后重 ...
- git使用命令行方式提交代码到github或gitlab上
(1)使用命令行(Git Bash)在gitlab上新建项目的流程 //进入项目目录下: C:\Users\wuwy>cd D:\workspace\eclipse\H5Patient\// ...