ITPub博客

首页 > IT职业 > IT生活 > python怎么判断是星期几

python怎么判断是星期几

IT生活 作者:sherrywong 时间:2021-09-11 10:24:31 0 删除 编辑

在 Python 的交互式解释器中先导入 time 模块,然后输入 [e for e in dir(time) if not e.startswith('_')] 命令,即可看到该模块所包含的

全部属性和函数:

>>> [e for e in dir(time) if not e.startswith('_')]
['altzone', 'asctime', 'clock', 'ctime', 'daylight', 'get_clock_info', 'gmtime', 'localtime', 'mktime', 'monotonic',
 'perf_counter', 'process_time', 'sleep', 'strftime', 'strptime', 'struct_time', 'time', 'timezone', 'tzname']

python编程操作日期时间主要用到的python模块是datetime和time这2个模块,time 模块主要包含各种提供日期、时间功能的类和函

数。该模块既提供了把日期、时间格式化为字符串的功能,也提供了从字符串恢复日期、时间的功能。

python获取今日日期

import datetime
today = datetime.date.today()
print(today)

输出:

2019-12-31

推荐学习《python教程》。

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/46/viewspace-2835012/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2019-04-12

  • 博文量
    83
  • 访问量
    593