Home > Article > Backend Development > Detailed explanation of the usage of StringAndDate in python
This article mainly introduces relevant information on simple examples of converting StringAndDate between python strings and dates. Friends in need can refer to
Converting between python strings and dates StringAndDate
The implementation code is given here and can be used directly. You can take a look.
Example code:
''''' 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
[Related recommendations]
1. Special recommendation:"php programmer Toolbox" V0.1 version download
3. Python object-oriented video tutorial
The above is the detailed content of Detailed explanation of the usage of StringAndDate in python. For more information, please follow other related articles on the PHP Chinese website!