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')
Output result:
Friday, 09-May-2008
For more articles related to Python time processing datetime examples, please pay attention to the PHP Chinese website!