Home > Backend Development > Python Tutorial > Python time processing datetime example

Python time processing datetime example

高洛峰
Release: 2017-01-12 15:23:18
Original
1265 people have browsed it

At the same time, datetime is also briefly introduced. Because there are many things that you need to use yourself, it is most effective to look for help.
Example:
Calculate the previous Friday and output it.
Answer:

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')
Copy after login

Output result:
Friday, 09-May-2008

For more articles related to Python time processing datetime examples, please pay attention to the PHP Chinese website!

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