网络编程
位置:首页>> 网络编程>> Python编程>> python 时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果代码详解

python 时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果代码详解

作者:贫僧来自东土大唐  发布时间:2021-10-28 05:37:14 

标签:python,2018

将时间信息“2018-02-04  18:23:35“ 解析成字典形式的结果

:{‘year':2018,‘month':2,‘day':4,‘hour':18:‘minute':23,‘second':35}

这道题有许多解法,可以用正则匹配,可以用时间模块等诸多方法。今天我又用类方法把这题写了一次。

废话少说,上代码


#将时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果,
# 如:{‘year':2018,‘month':2,‘day':4,‘hour':18:‘minute':23,‘second':35}
def t_time(*args):
 class Time():
   def __str__(self):
     return('year:{},month:{},day:{},hour:{},minute:{},second:{}'
         .format(self.y,self.m,self.d,self.h,self.M,self.s) )
 t=Time()
 t.y=2018;t.m=2;t.d=4
 t.h=18;t.M=23;t.s=35
 return t
print(t_time())

python 时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果代码详解

总结

以上所述是小编给大家介绍的python 时间信息“2018-02-04 18:23:35“ 解析成字典形式的结果网站的支持!

来源:https://blog.csdn.net/qq_41832483/article/details/80007837

0
投稿

猜你喜欢

手机版 网络编程 asp之家 www.aspxhome.com