【python】time,datetime,string相互转换
2017-11-13 18:30
501 查看
python 字符串和日期之间转换 StringAndDate
''''' 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
相关文章推荐
- python time, datetime, string, timestamp相互转换
- 【python】time,datetime,string相互转换
- 【python】time,datetime,string相互转换
- 【python】----- time,datetime,string相互转换
- ]python time, datetime, string, timestamp相互转换
- python中date、datetime、string的相互转换
- python time,datetime,string转换
- python中date、datetime、string的相互转换
- python中date、datetime、string的相互转换
- python中date、datetime、string的相互转换
- python时间模块time,时间戳,结构化时间,字符串时间,相互转换,datetime
- python中date、datetime、string的相互转换
- python中date、datetime、string的相互转换
- python中date、datetime、string的相互转换
- python中date、datetime、string的相互转换
- date、datetime、string的相互转换
- python基础学习——列表(list), 元祖(tuple), 字典(dict), 字符串(string), 集合(set) 介绍及相互转换
- python中time类型,datetime类型的关系与互相转换
- python list string相互转换
- python实现字典(dict)和字符串(string)的相互转换方法