需要解决的问题:时区问题
解决方案:引入pytz
封装的方法如下:
import datetime
from .. import pytzweek_list = ["星期一", "星期二", "星期三", "星期四", "星期五", "星期六", "星期日"]
now = datetime.datetime.now(pytz.timezone("Asia/Shanghai"))def get_weekday():"""Gets the day of the week based on the current time."""return week_list[now.weekday()]
测试方法如下:
import unittest
import ztimeclass TestNowGetWeekday(unittest.TestCase):def test_get_weekday(self):print(ztime.now.get_weekday())
测试结果如下: