python作为现在很流行的一门语言,学好python是很有必要的,下面是根据日期判断周几的个人总结的一些方法,可供参考。
Python如何根据日期判断周几
Python判断周几主要使用了time, datetime库,具体实现方法如下。
方法一:#!/usr/bin/python
# -*- coding:utf-8 -*-
from datetime import datetime
today = datetime.now().weekday() + 1
print(today)
week = datetime.strptime("20191018","%Y%m%d").weekday() + 1
print(week)
方法二:#!/usr/bin/python
# -*- coding:utf-8 -*-
from datetime import datetime
apply_time = 20191018
apply_time = datetime.utcfromtimestamp(apply_time)
time_str = apply_time.strftime("%Y-%m-%d %H:%M:%S")
apply_hour = time_str.split(" ")[1].split(":")[0]
apply_week = datetime.strptime(time