`
zzysh
  • 浏览: 53336 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Python date测试

阅读更多
import datetime, calendar

today = datetime.date.today()
oneday = datetime.timedelta(days=1)

# loop back to most recent Friday (could be today)
# takes care of end of month and even leap years

friday = today
while friday.weekday() != calendar.FRIDAY:
	friday -=oneday

oneweek = datetime.timedelta(days=7)
nextweek = today + oneweek
nextyear = today.replace(year=today.year+1)

print "Today (year-month-day) = ", today
print "Most recent Friday = ", friday
print "One week from today = ", nextweek
print "One year from today = ", nextyear
print "Current time = ", datetime.datetime.now().time() # just the time
print "Lunchtime = ", datetime.time(12,00) #12:00:00

print '-'*50

# a typical birthday year, month, day
birthday = datetime.date(1977,4,27)
# three diffeerent ways to present a date
# 1977-04-27
print "Birthday format1: ", birthday
# 04/27/77
print "Birthday format2: ", birthday.strftime("%m/%d/%y")
# 01Apr1977
print "Birthday format3: ", birthday.strftime("%d %b %Y")

age = today - birthday
print "You are ", age.days, "days old today!"

# extract the year from todays date
thisyear = int(today.strftime("%Y")[0:4])

# party message (include date and time)
rightnow = datetime.datetime.today()
bparty = datetime.datetime(thisyear, 4, 27, 14, 30)
# check if you can still make it to the party ...
if bparty > rightnow:
	print "Birthday party", bparty
else:
	print "Mised this year's birthday party!"

print '-'*50

# calculate days till xmas of this year
xmas = datetime.date(thisyear, 12, 25)
tillXmas = xmas - today
print "There aere %d days till xmas!" % tillXmas.days

print '-'*50

# add days to a given date
delta = datetime.timedelta(days=77)
addDays = today + delta
print "Today 's date is 			 :", today.strftime("%d%b%Y")
print "77 days from today it will be :", addDays.strftime("%d%b%Y")

print '-'*50

Weekday = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 
	'Saturday', 'Sunday']

print "Today is ", Weekday[datetime.date.weekday(today)]
分享到:
评论

相关推荐

    NextDate函数

    软件测试NextDate函数测试用例 System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ffff"); //2008年04月24 15时56分48秒 System.DateTime.Now.ToString("yyyy年MM月dd HH时mm分ss秒"); //星期二, 四月 24 ...

    分别基于传统方法和深度学习方法实现意图识别python源码+数据集+项目说明.zip

    * python -u train.py -dd {$DATE} LR * python -u train.py -dd {$DATE} Stack-Propagation * python -u train.py -dd {$DATE} Bi-model with decoder * python -u train.py Bi-LSTM * python -u train.py...

    python opencv实现运动检测

    本文实例为大家分享了python opencv运动检测的具体代码,供大家参考,具体内容如下 # -*- coding:utf-8 -*- __author__ = 'kingking' __version__ = '1.0' __date__ = '14/07/2017' import cv2 import numpy as np ...

    Python银行反欺诈项目代码,数据已脱敏处理。

    Python银行反欺诈项目代码,数据已脱敏处理,并只保留了部分...数据中有flag,in_date,ip,terminaltype phone,versioncode,userno,certno这几列,根据训练集进行学习,在测试集上进行测试,得到还不错的评估指标。

    基于传统方法和深度学习方法实现意图识别python源码+数据集+项目说明.zip

    * python -u train.py -dd {$DATE} LR * python -u train.py -dd {$DATE} Stack-Propagation * python -u train.py -dd {$DATE} Bi-model with decoder * python -u train.py Bi-LSTM * python -u train.py ...

    Python-3.8.0a3.tgz

    当Python解释器被Ctrl-C(SIGINT)中断并且KeyboardInterrupt未捕获到的结果异常时,Python进程现在通过SIGINT信号或正确的退出代码退出,以便调用进程可以检测到它因Ctrl而死亡-C。POSIX和Windows上的shell使用它来...

    HTMLTestRunner中文版Python3.X

    path= 'D:/Python_test/'+ date +"/login/"+time+"/" #定义报告文件路径和名字,路径为前面定义的path,名字为report(可自定义),格式为.html report_path = path+"report.html" #判断是否定义的路径目录...

    Python-3.8.0b2.tgz

    当Python解释器被Ctrl-C(SIGINT)中断并且KeyboardInterrupt未捕获到的结果异常时,Python进程现在通过SIGINT信号或正确的退出代码退出,以便调用进程可以检测到它因Ctrl而死亡-C。POSIX和Windows上的shell使用它来...

    python-3.8.0a4.exe

    当Python解释器被Ctrl-C(SIGINT)中断并且KeyboardInterrupt未捕获到的结果异常时,Python进程现在通过SIGINT信号或正确的退出代码退出,以便调用进程可以检测到它因Ctrl而死亡-C。POSIX和Windows上的shell使用它来...

    python3.7解析eml文件

    通过对eml文件的解析获得其中的from、to、date、subject、body、atta 该文件可以实现基本功能,未经过严格测试,可能存在一定缺陷和BUG

    python检测远程服务器tcp端口的方法

    本文实例讲述了python检测远程服务器tcp端口的方法。分享给大家供大家参考。具体如下: python检测远程服务器tcp端口的代码,这段代码可以用来做服务器监控实用 #!/usr/bin/env python #coding:utf-8 #filename:tcp...

    基于python+Jupyter Notebook+神经网络的言情小说检测识别(高检测率)+源码+开发文档(毕设&课设&项目开发

    基于python+Jupyter Notebook+神经网络的言情小说检测识别(高检测率)+源码+开发文档,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用~ 基于python+Jupyter ...

    python-3.8.0b2-amd64.exe

    当Python解释器被Ctrl-C(SIGINT)中断并且KeyboardInterrupt未捕获到的结果异常时,Python进程现在通过SIGINT信号或正确的退出代码退出,以便调用进程可以检测到它因Ctrl而死亡-C。POSIX和Windows上的shell使用它来...

    利用Python实现网络测试的脚本分享

    最近同学让我帮忙写一个测试网络的工具。由于工作上的事情,断断续续地拖了很久才给出一个相对完整的版本。其实,我Python用的比较少,所以基本都是边查资料边写程序。 程序的主要逻辑如下: 读取一个excel文件中的...

    Python实现调用另一个路径下py文件中的函数方法总结

    本文实例讲述了Python实现调用另一个路径下py文件中的函数...主文件(main_preprocess.py)需要运用split_by_date.py中的函数,main_preprocess与split_by_date在同一个大文件夹下,其中split_by_date在preprocess文件

    Test-Driven Development with Python, 2nd Edition, 2017

    Title: Test-Driven Development with Python, 2nd Edition Length: 592 pages Edition: 2 Language: English Publication Date: 2017-08-10 ISBN-10: 1491958707 ISBN-13: 9781491958704 Table of Contents Part I...

    Frozengun:让您的Python测试历经时

    FreezeGun:让您的Python测试随着时间的流逝 FreezeGun是一个库,通过模拟datetime模块,您的Python测试可以穿越时间。 用法 调用装饰器或上下文管理器后,对datetime.datetime.now(),datetime.datetime.utcnow...

    python-isodate-0.5.0-3.el7.noarch.rpm

    官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装

    python pandas生成时间列表

    python生成一个日期列表 首先导入pandas import pandas as pd def get_date_list(begin_date,end_date): date_list = [x.strftime('%Y-%m-%d') for x in list(pd.date_range(start=begin_date, end=end_date))] ...

Global site tag (gtag.js) - Google Analytics