Zed*_*edx 6 python datetime calendar
使用日历库在 python 中突出显示当前日期。下面是我的程序。
import calendar
c = calendar.TextCalendar(calendar.MONDAY)
str = c.formatmonth(2018,1)
print (str)
Run Code Online (Sandbox Code Playgroud)
我从常规日历切换到 HTMLCalendar ;在今天的日期周围添加了额外的 html 标签;显示新日历。
它是为 jupyter 笔记本编写的。对于ipython Interactive来说可以做到,但是格式化比较麻烦。
import calendar
import datetime as dt
from IPython.display import display,HTML
# find out today's date
t = dt.datetime.today()
# create HTML Calendar month
cal = calendar.HTMLCalendar()
s= cal.formatmonth (t.year,t.month)
# display calendar without highlighting today
display(HTML(s))
# add cell's backgroundcolor, bold and underling html tags
# around today's date
ss = s.replace('>%i<'%t.day, ' bgcolor="#66ff66"><b><u>%i</u></b><'%t.day)
display(HTML(ss))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4478 次 |
| 最近记录: |