python time 计算日期
来源:互联网 发布:中国联通塞班岛网络 编辑:程序博客网 时间:2024/05/20 20:18
计算week
因为issue report 很多情况下按周report,所以用Python实现自动issue tracking时难免会用第几周作为图形的下标
def cal_label(self, date):
m = re.search('(\d+)([^\d])(\d+)([^\d](\d+))', date)
if self.step == 'all':
res = 'all'
elif self.step == 'year':
res = m.group(1)
elif self.step == 'month':
res = r''.join(m.group(1,2,3))
elif self.step == 'week':
#TODO guard
form = '%Y{0}%m{0}%d'.format(m.group(2))
week = time.strftime('%W %w', time.strptime(date, form))
[W, w] = re.split(' ', week)
res = W + 'W'
else:
ValueError("can't support other format, %s" %(self.step))
return(str(res))
这里引用一下‘一个人的天空’的博客,关于Python time module的详细用法可以去那里看:
http://www.cnblogs.com/qq78292959/archive/2013/03/22/2975786.html
这里已知‘2017/3/3’ format string, 所以先strptime成stuct_time然后strftime成format string,
%W表示第几周
%w表示本周的第几天
还有另一种方法用datetime
import datetime
datetime.datetime(2017,3,3).isocalendar()
- python time 计算日期
- python基础------日期time
- python 日期时间计算
- Python计算日期差
- python中的日期计算
- Java日期计算之Joda-Time
- Java日期计算之Joda-Time
- Java日期计算之Joda-Time
- Java日期计算之Joda-Time
- Python模块学习 ---- time 日期时间处理
- Python模块学习 ---- time 日期时间处理
- Python模块学习 ---- time 日期时间处理
- python time时间,日期,时间戳处理
- Python time 100 天以后的日期
- 【Python】Python_learning5:使用python计算生日日期
- python 计算下一个星期三的日期
- python 计算两个带日期的时间差
- python 计算N天之后的日期
- block,inline和inline-block概念和区别
- 卷积神经网络(CNN)前向传播算法
- 堆排序
- 【河工大老弱病残康复训练(2)】--C
- Kali中安装Android Studio
- python time 计算日期
- 【伪原创?】超级啰嗦的unity入门笔记之小物体的旋转(物体的自转和绕其他体的旋转)
- 项目整体搭建。
- 龙虎和程序开发-龙虎和网站定制
- Hibernate中四种对象状态,Session常用方法,映射类型
- 1.1分布式学习流程
- C语言 · 报时助手
- Tomcat指定主机访问怎么弄?
- ACM选拔所思