Task 8 模块与datetime模块

datetime模块

datetime类

class datetime(date):
    def __init__(self, year, month, day, hour, minute, second, microsecond, tzinfo)
        pass
    def now(cls, tz=None):
        pass
    def timestamp(self):
        pass
    def fromtimestamp(cls, t, tz=None):
        pass
    def date(self):
        pass
    def time(self):
        pass
    def year(self):
        pass
    def month(self):
        pass
    def day(self):
        pass
    def hour(self):
        pass
    def minute(self):
        pass
    def second(self):
        pass
    def isoweekday(self):
        pass
    def strftime(self, fmt):
        pass
    def combine(cls, date, time, tzinfo=True):
        pass

date类

class date:
    def __init__(self, year, month, day):
        pass
    def today(cls):
        pass

time类

class time:
    def __init__(self, hour, minute, second, microsecond, tzinfo):
        pass

timedelta类

class timedelta(SupportsAbs[timedelta]):
    def __init__(self, days, seconds, microseconds, milliseconds, minutes, hours, weeks,):
        pass
    def days(self):
        pass
    def total_seconds(self):
        pass

练习题

1、假设你获取了用户输入的日期和时间如2020-1-21 9:01:30,以及一个时区信息如UTC+5:00,均是str,请编写一个函数将其转换为timestamp:

题目说明:

“”"

Input file
example1: dt_str=‘2020-6-1 08:10:30’, tz_str=‘UTC+7:00’
example2: dt_str=‘2020-5-31 16:10:30’, tz_str=‘UTC-09:00’

Output file
result1: 1590973830.0
result2: 1590973830.0
“”"

def to_timestamp(dt_str, tz_str):
    # your code here
        pass

2、编写Python程序以选择指定年份的所有星期日。

题目说明:

“”"
Input file
2020

Output file
2020-01-05
2020-01-12
2020-01-19
2020-01-26
2020-02-02

2020-12-06
2020-12-13
2020-12-20
2020-12-27
“”"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Python中获取毫秒,可以使用time模块中的time()函数来获取当前时间戳,然后将其乘以1000。时间戳是以秒为单位的浮点数,所以乘以1000可以将其转换为毫秒。以下是一个示例代码: ```python import time milliseconds = time.time() * 1000 print(milliseconds) ``` 这将输出当前时间的毫秒表示。请注意,时间戳是相对于1970年1月1日午夜(历元)的时间间隔。 #### 引用[.reference_title] - *1* [Python时间模块之time模块](https://blog.csdn.net/json_ligege/article/details/128202251)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Python计算程序运行时间秒级/毫秒级的两种方法datetime和time](https://blog.csdn.net/qq_39691492/article/details/120782415)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [python time 模块](https://blog.csdn.net/Hua_rong/article/details/115675592)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值