編程世界中,Python是一種廣泛使用的高級編程語言,其簡單易學(xué)的特點(diǎn)吸引了眾多初學(xué)者。Python提供了許多內(nèi)置模塊和庫,其中之一就是calendar模塊。在 Python 中,我們已經(jīng)學(xué)習(xí)了datetime,time等處理時(shí)間跟日期的模塊。今天我們來學(xué)習(xí)下calendar 模塊,calendar 為我們提供了處理日期、時(shí)間和日歷的功能。它可以幫助我們生成日歷,管理日期,并執(zhí)行一些基本的日期計(jì)算。讓我們一起深入了解 calendar 模塊的基本用法和功能。
一. 導(dǎo)入 calendar 模塊
import calendar
二. 基本用法
1.獲取指定年份的日歷
>>> import calendar
>>> year_calendar=calendar.TextCalendar(calendar.SUNDAY)
>>> year=2023
>>> print(year_calendar.formatyear(year))
這個(gè)例子展示了如何使用 TextCalendar 類來獲取指定年份的日歷,并使用 formatyear() 方法格式化輸出。
2.獲取指定月份的日歷
>>> month_calendar=calendar.TextCalendar(calendar.SUNDAY)
>>> year=2023
>>> month=12
>>> print(month_calendar.formatmonth(year, month))
formatmonth() 方法用于獲取指定年份和月份的日歷。
3. 獲取一個(gè)月的天數(shù)
calendar.monthrange(year, month) 是一個(gè)Python內(nèi)置函數(shù),用于返回指定年份和月份的日歷信息。它返回一個(gè)包含兩個(gè)元素的元組,第一個(gè)元素是指定月份的第一天是星期幾(0表示星期一,6表示星期日),第二個(gè)元素是指定月份的總天數(shù)
>>> import calendar
>>> month=calendar.monthrange(2023, 12)[1]
>>> print(month)
31
獲取指定月份第一天是星期幾
>>> import calendar
>>> first=calendar.monthrange(2023, 12)[0]
>>> print(first)
4
4. 實(shí)際應(yīng)用場景
calendar 模塊在日程管理、日期操作、特定日期的計(jì)算等方面有著廣泛的應(yīng)用。比如在日歷應(yīng)用、計(jì)劃任務(wù)、會議安排等領(lǐng)域。
5. 注意事項(xiàng)
calendar 模塊提供了一些常用的方法來處理日期和日歷,但并不包含所有的日期處理功能。
注意 firstweekday 參數(shù),它指定了一周的起始日,默認(rèn)為星期一。
總結(jié)
calendar 模塊是 Python 中處理日歷和日期的強(qiáng)大工具,提供了生成日歷、管理日期和執(zhí)行日期計(jì)算的功能。通過了解其基本用法和方法,你可以更好地處理日期和日歷相關(guān)的操作。
更多用法參考官方文檔
https://docs.python.org/3/library/calendar.html?highlight=calendar
ullcalendar 一款 star高達(dá)12.6K+ 基于jQuery實(shí)現(xiàn)的管理日程安排、工作計(jì)劃的日歷工具。今天給大家分享如何在Vue框架下使用FullCalendar。
fullcalendar-vue 基于FullCalendar.js的Vue版本實(shí)現(xiàn)。支持增刪改查及拖拽式管理日程安排。
安裝
$ npm i @fullcalendar/vue @fullcalendar/daygrid -S
使用插件
<template>
<FullCalendar :options="calendarOptions" />
</template>
<script>
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import interactionPlugin from '@fullcalendar/interaction'
export default {
components: {
FullCalendar
},
data() {
return {
calendarOptions: {
plugins: [ dayGridPlugin, interactionPlugin ],
headerToolbar: {
left: 'prev,next today'
center: 'title',
right: 'dayGridMonth,timeGridWeek,timeGridDay'
},
initialView: 'dayGridMonth',
editable: true,
selectable: true,
dateClick: this.handleDateClick,
events: [
{ title: '開學(xué)安排', date: '2020-09-01' },
{ title: '課表排班', date: '2020-09-02' }
],
eventClick: this.handleEventClick,
}
}
},
methods: {
handleDateClick(arg) {
alert('date click! ' + arg.dateStr)
},
handleEventClick(info) {
alert('Event:' + info.event.title)
info.el.style.borderColor='red'
info.evnet.remove()
}
}
}
</script>
Fullcalendar官網(wǎng)還提供了在React和Angular框架下使用方法。
https://fullcalendar.io/docs/react
https://github.com/fullcalendar/fullcalendar-react
https://fullcalendar.io/docs/angular
https://github.com/fullcalendar/fullcalendar-angular
# fullcalendar文檔
https://fullcalendar.io/
https://www.helloweba.net/search.html?keys=fullcalendar
# 項(xiàng)目地址
https://github.com/fullcalendar/fullcalendar
最后附上fullcalendar的vue版本項(xiàng)目地址
# 文檔地址
https://fullcalendar.io/docs/vue
# 倉庫地址
https://github.com/fullcalendar/fullcalendar-vue
ok,就介紹到這里。感興趣的可以去看下哈,歡迎一起交流討論!
在前端網(wǎng)頁設(shè)計(jì)HTML中,無論是css還是JavaScript都是非常重要的,但是有些動(dòng)態(tài)效果只能由我們的js來實(shí)現(xiàn),今天小編就給大家一個(gè)厲害的干貨,希望大家多多關(guān)注小編呢!
js日歷
十二個(gè)月份,下方是每個(gè)月內(nèi)容框,當(dāng)鼠標(biāo)移入上放月份時(shí),下方內(nèi)容框自動(dòng)變換內(nèi)容.
各大博客網(wǎng)站,均有此JavaScript的代碼實(shí)現(xiàn),是基礎(chǔ)入門必不可少的技能!
JavaScript部分
css部分
HTML部分
小伙伴們要自己動(dòng)動(dòng)手敲一遍代碼哦!前端代碼也是實(shí)戰(zhàn)出成果的!!!小編會一直支持大家學(xué)習(xí),也希望大家多多支持小編哦,嘻嘻(#^.^#),關(guān)注小編
*請認(rèn)真填寫需求信息,我們會在24小時(shí)內(nèi)與您取得聯(lián)系。