Python weeks and days of the week

1. Mutual conversion of time format date, datetime, string

2. Get the week and day of the week: W is the week, w is the day of the week, and the upper and lower case have different meanings

#! /usr/bin/env python
# -*- coding:utf-8 -*-
import time
import datetime

#str 转datetime
str = '2012-11-19'
date_time = datetime.datetime.strptime(str,'%Y-%m-%d')
print date_time

#获取当前时间
t_date=datetime.date.today()
print t_date
#获取第几周
week = t_date.strftime("%W")
print(week)
#获取星期几
week_day = t_date.strftime("%w")
print week_day

 

Guess you like

Origin blog.csdn.net/u013347671/article/details/83143745