Home > Backend Development > Python Tutorial > Python 时间处理datetime实例

Python 时间处理datetime实例

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-16 08:47:34
Original
1021 people have browsed it

同时,关于datetime也是简单介绍。因为有很多东西需要自己去使用,去查帮助才最有效。
例子:
计算上一个星期五并输出。
解答:

复制代码 代码如下:

import datetime, calendar

lastFriday = datetime.date.today( )
oneday = datetime.timedelta(days=1)
lastFriday -= oneday
while lastFriday.weekday( ) != calendar.FRIDAY:
lastFriday -= oneday
print lastFriday.strftime('%A, %d-%b-%Y')

输出结果:
Friday, 09-May-2008
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template