存档

文章标签 ‘有用,代码,片断’

有用python代码片断

2016年1月14日 没有评论

1 日期与字符串转换

#convert a string to a datetime object
from datetime import datetime
date_obj = datetime.strptime(‘May 29 2015 2:45PM’, ‘%B %d %Y %I:%M%p’)

#converting datetime object to a formatted string
from datetime import datetime
date_obj = datetime.now()
date_string = date_obj.strftime(‘%B %d %Y %I:%M%p’)

阅读全文…