Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> Python

วิธีตั้ง First Day of Week เป็น Weekday ใน Python

ใน Module calendar มี Function setfirstweekday() ตั้ง First Day ของแต่ละสัปดาห์ด้วย Code ของ Weekday ที่ให้มา ส่งผลต่อ Display Functions เช่น prmonth เท่านั้น

ตัวอย่าง

import calendar

print(calendar.prmonth(2018, 1))
calendar.setfirstweekday(calendar.SUNDAY)
print(calendar.prmonth(2018, 1))

ผลลัพธ์

    January 2018
Mo Tu We Th Fr Sa Su
 1  2  3  4  5  6  7
 8  9 10 11 12 13 14
...

    January 2018
Su Mo Tu We Th Fr Sa
    1  2  3  4  5  6
 7  8  9 10 11 12 13
...

ค่าคงที่: calendar.MONDAY (0) ถึง calendar.SUNDAY (6) Default คือ MONDAY