python 字符串和日期之间转换 StringAndDate
这里给出实现代码,直接可以使用。大家可以看下。
实例代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ''''' Created on 2013-7-25 @author: Administrator ''' from datetime import datetime class StringAndDate( object ): ''''' String to Date(datetime) or date to string ''' def stringToDate( self ,string): #example '2013-07-22 09:44:15+00:00' dt = datetime.strptime(string, "%Y-%m-%d %H:%M:%S+00:00" ) #print dt return dt ''''' Date(datetime) to String ''' def dateToString( self ,date): ds = date.strftime( '%Y-%m-%d %H:%M:%S' ) return ds ''''' return n hours after datetime ''' def getAfterDate( self ,n): dnow = datetime.datetime.now() dafter = dnow + datetime.timedelta(hours = n) #dafter.ctime() return dafter |
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
原文链接:http://blog.csdn.net/jiyingying_up/article/details/9929597