datetime对象与字符串可以互相转化

代码如下:

 

 1 from datetime import datetime
 2 
 3 
 4 def datetime_string(time):
 5     return time.strftime("%Y-%m-%d %H:%M:%S")
 6 # datetime对象转换字符串
 7 
 8 
 9 def string_datetime(string):
10     return datetime.strftime(string, "%Y-%m-%d %H:%M:%S")
11 # 字符串对象转换datetime对象

 

相关文章:

  • 2021-10-06
  • 2021-04-17
  • 2021-11-11
  • 2021-07-10
  • 2021-09-24
  • 2021-11-22
  • 2022-12-23
  • 2021-09-13
猜你喜欢
  • 2021-07-28
  • 2022-01-11
  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
相关资源
相似解决方案