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函数测试用例 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 -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运动检测的具体代码,供大家参考,具体内容如下 # -*- coding:utf-8 -*- __author__ = 'kingking' __version__ = '1.0' __date__ = '14/07/2017' import cv2 import numpy as np ...
Python银行反欺诈项目代码,数据已脱敏处理,并只保留了部分...数据中有flag,in_date,ip,terminaltype phone,versioncode,userno,certno这几列,根据训练集进行学习,在测试集上进行测试,得到还不错的评估指标。
* 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解释器被Ctrl-C(SIGINT)中断并且KeyboardInterrupt未捕获到的结果异常时,Python进程现在通过SIGINT信号或正确的退出代码退出,以便调用进程可以检测到它因Ctrl而死亡-C。POSIX和Windows上的shell使用它来...
path= 'D:/Python_test/'+ date +"/login/"+time+"/" #定义报告文件路径和名字,路径为前面定义的path,名字为report(可自定义),格式为.html report_path = path+"report.html" #判断是否定义的路径目录...
当Python解释器被Ctrl-C(SIGINT)中断并且KeyboardInterrupt未捕获到的结果异常时,Python进程现在通过SIGINT信号或正确的退出代码退出,以便调用进程可以检测到它因Ctrl而死亡-C。POSIX和Windows上的shell使用它来...
当Python解释器被Ctrl-C(SIGINT)中断并且KeyboardInterrupt未捕获到的结果异常时,Python进程现在通过SIGINT信号或正确的退出代码退出,以便调用进程可以检测到它因Ctrl而死亡-C。POSIX和Windows上的shell使用它来...
通过对eml文件的解析获得其中的from、to、date、subject、body、atta 该文件可以实现基本功能,未经过严格测试,可能存在一定缺陷和BUG
本文实例讲述了python检测远程服务器tcp端口的方法。分享给大家供大家参考。具体如下: python检测远程服务器tcp端口的代码,这段代码可以用来做服务器监控实用 #!/usr/bin/env python #coding:utf-8 #filename:tcp...
基于python+Jupyter Notebook+神经网络的言情小说检测识别(高检测率)+源码+开发文档,适合毕业设计、课程设计、项目开发。项目源码已经过严格测试,可以放心参考并在此基础上延申使用~ 基于python+Jupyter ...
当Python解释器被Ctrl-C(SIGINT)中断并且KeyboardInterrupt未捕获到的结果异常时,Python进程现在通过SIGINT信号或正确的退出代码退出,以便调用进程可以检测到它因Ctrl而死亡-C。POSIX和Windows上的shell使用它来...
最近同学让我帮忙写一个测试网络的工具。由于工作上的事情,断断续续地拖了很久才给出一个相对完整的版本。其实,我Python用的比较少,所以基本都是边查资料边写程序。 程序的主要逻辑如下: 读取一个excel文件中的...
本文实例讲述了Python实现调用另一个路径下py文件中的函数...主文件(main_preprocess.py)需要运用split_by_date.py中的函数,main_preprocess与split_by_date在同一个大文件夹下,其中split_by_date在preprocess文件
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...
FreezeGun:让您的Python测试随着时间的流逝 FreezeGun是一个库,通过模拟datetime模块,您的Python测试可以穿越时间。 用法 调用装饰器或上下文管理器后,对datetime.datetime.now(),datetime.datetime.utcnow...
官方离线安装包,测试可用。使用rpm -ivh [rpm完整包名] 进行安装
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))] ...