def process_date(self):
start = datetime.datetime(2021,3,15,12,34,34)
print(start,type(start))
# timedelta提供参数
# days: float = ...,
# seconds: float = ...,
# microseconds: float = ...,
# milliseconds: float = ...,
# minutes: float = ...,
# hours: float = ...,
# weeks: float = ...,
end = start + datetime.timedelta(weeks=12,days=12)
print(end)
# 直接减就能获取时间差
print(end-start)
# datetime 转 str
str_start = start.strftime("%y-%m-%d")
print(str_start,type(str_start))
# str 转 datetime
datetime_parser = parse(str_start)
print(datetime_parser,type(datetime_parser))
# str 转 datetime
datetime_start = datetime.datetime.strptime(str_start,"%y-%m-%d")
print(datetime_start,type(datetime_start))
# str 转 datetime
str_obj = self.get_df()["datetime"]
# print(str_obj)
# str 转 datetime
pd_datetime = pd.to_datetime(str_obj)
print(pd_datetime,type(pd_datetime))
rea = pd.date_range(start="1999.04.23 12:22:22",periods=2 ,normalize=True)
for i in rea:
datetime_parser_ = parse(str(i))
print(datetime_parser_,type(datetime_parser_))
"""
2021-03-15 12:34:34 <class 'datetime.datetime'>
2021-06-19 12:34:34
96 days, 0:00:00
21-03-15 <class 'str'>
2015-03-21 00:00:00 <class 'datetime.datetime'>
2021-03-15 00:00:00 <class 'datetime.datetime'>
0 2021-01-04
1 2021-01-04
2 2021-01-04
3 2021-01-04
4 2021-01-04
...
125233 2021-10-12
125234 2021-10-12
125235 2021-10-12
125236 2021-10-12
125237 2021-10-12
Name: datetime, Length: 125238, dtype: datetime64[ns] <class 'pandas.core.series.Series'>
1999-04-23 00:00:00 <class 'datetime.datetime'>
1999-04-24 00:00:00 <class 'datetime.datetime'>
"""
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/156902.html