码迷,mamicode.com
首页 > 编程语言 > 详细

python日期与字符串互转

时间:2018-09-28 19:16:38      阅读:153      评论:0      收藏:0      [点我收藏+]

标签:https   str   csdn   pretty   ring   name   source   ftime   word   

1str -> date

import datetime

detester = ‘2017-01-01date = datetime.datetime.strptime(detester,’%Y-%m-%d‘)

2date -> str

import datetime

date = datetime.now()

detester = date.strftime(‘%Y-%m-%d‘)

--------------------- 本文来自 criller 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/criller/article/details/73715057?utm_source=copy 

PS:若时间格式为前段传回,有可能字符串后面有空格,会报错。可len()查看处理

python日期与字符串互转

标签:https   str   csdn   pretty   ring   name   source   ftime   word   

原文地址:https://www.cnblogs.com/wrxblog/p/9719881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!