以下全部引入

  form datetime import datetime, timedelta

  import time

一、time 转str

  

 

 

二、datetime 转 str

  str_date = datetime.now().strftime("%Y-%m-%d")   -------(%04d%02d%02d)此种格式化注意

 

三、str 转 datetime

  start_date = datetime.strptime("2016-06-07", "%Y-%m-%d")  

四、实例应用

def datelist(start, end):
    start_date = datetime.strptime(start, "%Y-%m-%d")
    end_date = datetime.strptime(end, "%Y-%m-%d")
    result = []
    curr_date = start_date
    while curr_date != end_date:
        # result.append("%04d-%02d-%02d" % (curr_date.year, curr_date.month, curr_date.day))
        result.append(curr_date.strftime("%Y-%m-%d"))
        curr_date += timedelta(1)
    # result.append("%04d-%02d-%02d" % (curr_date.year, curr_date.month, curr_date.day))
    result.append(curr_date.strftime("%Y-%m-%d"))
    return result

if __name__ == "__main__":
    print datelist("2016-06-07", "2016-06-27") 

  

 

 

 

 

----------2016-6-29 15:51:03--

    source: 【1】python string to datetime datetime to string


 
                    
            
                

相关文章:

  • 2021-10-21
  • 2021-11-11
  • 2022-12-23
  • 2021-11-04
  • 2021-12-29
  • 2021-09-02
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-07-08
  • 2021-09-02
  • 2022-12-23
  • 2021-06-26
相关资源
相似解决方案