四川城乡建设网站,莱芜金点子广告电子版最新,贵阳网站建设设计,满屏网站设计做多大文章目录 【calendar】是否闰年星期英文缩写今天星期几打印日历 【datetime】今天星期几 【time】当前时间 【pandas】当前时间文件修改的时间 【日历】 【calendar】
是否闰年
import calendar
print(calendar.isleap(2000))out
True星期英文缩写
print(calendar.weekhead… 文章目录 【calendar】是否闰年星期英文缩写今天星期几打印日历 【datetime】今天星期几 【time】当前时间 【pandas】当前时间文件修改的时间 【日历】 【calendar】
是否闰年
import calendar
print(calendar.isleap(2000))out
True星期英文缩写
print(calendar.weekheader(4)) out
Mon Tue Wed Thu Fri Sat Sun 今天星期几
print(calendar.weekday(2023, 9, 11)) # index, 0~6
print(calendar.day_name[calendar.weekday(2023, 9, 11)])out
0
Monday打印日历
print(calendar.prmonth(2023, 9)) output September 2023
Mo Tu We Th Fr Sa Su1 2 34 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30
None今天星期几对应英文
import calendar
print(calendar.weekday(2022, 3, 24)) # 0~6
3 Thursday
【datetime】
今天星期几
# weekday
import datetime
week_list [星期一,星期二,星期三,星期四,星期五,星期六,星期七]
print(week_list[datetime.date(2022, 3, 24).weekday()]) # 返回 0~6星期四
import datetime
print(datetime.date(2022,3,24).isoweekday()) # 返回 1~74
import datetime
print(datetime.date(2022,3,24).strftime(%A))
print(datetime.date(2022,3,24).strftime(%a))Thursday Thu import pandas as pd
from datetime import datetimedf pd.DataFrame({name: [张三, 李四, 王五],date: [datetime(2022,3,22), datetime(2022,3,23), datetime(2022,3,24)]
})
print(df,\n)df[week_num1] df[date].dt.dayofweek
df[week_num2] df[date].dt.weekday
df[week_name] df[date].dt.day_name()print(df)output name date
0 张三 2022-03-22
1 李四 2022-03-23
2 王五 2022-03-24 name date week_num1 week_num2 week_name
0 张三 2022-03-22 1 1 Tuesday
1 李四 2022-03-23 2 2 Wednesday
2 王五 2022-03-24 3 3 Thursday【time】
肝了3天整理了80个Python DateTime 例子必须收藏
当前时间
import time
t time.localtime()
print (time.asctime(t))output
Tue May 24 11:50:38 2022gmtime 和 strftime
from time import gmtime,strftime
print(strftime(%a, %d %b %Y %H:%M:%S, gmtime()))
print(strftime(%A, gmtime())) # 星期
print(strftime(%D, gmtime())) # 日期
print(strftime(%B, gmtime())) # 月份
print(strftime(%y, gmtime())) # 年份# Convert seconds into GMT date
print(strftime(%a, %d %b %Y %H:%M:%S, gmtime(1)))
print(strftime(%a, %d %b %Y %H:%M:%S, gmtime(123456789)))Tue, 24 May 2022 11:50:38
Tuesday
05/24/22
May
22
Thu, 01 Jan 1970 00:00:01
Thu, 29 Nov 1973 21:33:09【pandas】
当前时间
import pandas as pd
print(pd.datetime.now())
print(pd.datetime.now().date())
print(pd.datetime.now().year)
print(pd.datetime.now().month)
print(pd.datetime.now().day)
print(pd.datetime.now().hour)
print(pd.datetime.now().minute)
print(pd.datetime.now().second)
print(pd.datetime.now().microsecond)output
2022-05-24 11:52:59.556948
2022-05-24
2022
5
24
11
52
59
557247文件修改的时间
import os
import timepth D://model/for roots, dirs, files in os.walk(pth):for file in files:obsolute_path os.path.join(roots, file)mtime os.stat(obsolute_path).st_mtimefile_modify_time time.strftime(%Y-%m-%d,%H:%M:%S, time.localtime(mtime))print({i} 修改时间是 {j}.format(iobsolute_path, jfile_modify_time))【日历】
STXINGKA.TTF 是华文行楷 参考 用Python自动化生成倒计时图片
from PIL import Image, ImageDraw, ImageFont
import osfor i in range(1, 22):# 创建图像,设置图像大小及颜色im Image.new(RGBA, (1000, 1800), (166, 12, 4, 255))draw ImageDraw.Draw(im)# 设置本次使用的字体fontsFolder C:\Windows\Fontsfont1 ImageFont.truetype(os.path.join(fontsFolder, STXINGKA.TTF), 420)font2 ImageFont.truetype(os.path.join(fontsFolder, STXINGKA.TTF), 40)# 计算各文本的放置位置txtSize_1 draw.textsize(距 离 除 夕 夜, font2)pos_x_1 (1000 - txtSize_1[0]) / 2txtSize_2 draw.textsize(还 有, font2)pos_x_2 (1000 - txtSize_2[0]) / 2txtSize_3 draw.textsize(天, font2)pos_x_3 (1000 - txtSize_3[0]) / 2txtSize_4 draw.textsize(不 是 年 味 越 来 越 少, font2)pos_x_4 (1000 - txtSize_4[0]) / 2txtSize_5 draw.textsize(而 是 我 们 都 长 大 了, font2)pos_x_5 (1000 - txtSize_5[0]) / 2# 设置文本放置位置,居中draw.text((pos_x_1, 200), 距 离 除 夕 夜, fill(217, 217, 217, 255), fontfont2)draw.text((pos_x_2, 300), 还 有, fill(217, 217, 217, 255), fontfont2)draw.text((pos_x_3, 1050), 天, fill(217, 217, 217, 255), fontfont2)draw.text((pos_x_4, 1350), 不 是 年 味 越 来 越 少, fill(137, 183, 109, 255), fontfont2)draw.text((pos_x_5, 1440), 而 是 我 们 都 长 大 了, fill(137, 183, 109, 255), fontfont2)# 绘制线框draw.line([(20, 20), (980, 20), (980, 1780), (20, 1780), (20, 20)], fill(217, 217, 217, 255), width5)# 设置变化的文本属性txtSize_6 draw.textsize(str(i), font1)pos_x_6 (1000 - txtSize_6[0]) / 2draw.text((pos_x_6, 500), str(i), fill(137, 183, 109, 255), fontfont1)# im.show()# 保存图像filename day str(i) .pngim.save(filename)生成了 1-21 天部分节选如下