In practice, there is a time to deal with the problem, need to be Sep, 19:30 (UTC time) and the current time compared sooner or later, know this 2014-09-06 19:30 format time operation. So, when you're dealing with it, you want to
The SEP format time is converted to the time of the following format, no correlation function is found, so he simply wrote a program, only in this, in case of query
The code is as follows:
#-*-Coding:utf-8-*-from datetime import datefrom datetime import datetimefrom datetime import timedelta# # #如果是返回当前时 Time.localtime () # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # time.gmtime () # lt = time.localtime () # TM = Time.gmtime () # = Time.strftim E ('%y-%m-%d%h-%m ', lt) # ft2 = Time.strftime ('%y-%m-%d%h:%m ', tm) # print ft, ft2# print '-------------------------------- ------------------------' # now = Datetime.datetime.now () # now = Now.replace (day = 1) # Print now# print now.time () # Mytim e = [' 2014-09-06 20:19 ']# #mytime2 = ' 2014-10-09 14:32 ' # str = "". Join (mytime) # print str# retime = datetime.strptime (str , '%y-%m-%d%h:%m ') # print retime# retime = Retime +timedelta (hours = 8) # print retime# # tdtime = DateTime.Now () # Print TD time# if Retime <= tdtime-timedelta (days = 7): # print "Too early" # #Sep, 19:30monthdic = {' Jan ': ' 01 ', ' Feb ': ' ' Mar ': ' The ' ', ' Apr ': ' A ', ' may ': ' ', ' June ': ' ', ' Jul ': ' ', ' ' ' ' ' ' ' ', ' Sep ': ' The ', ' ' Oct ': ' 11 ', ' Dec ': '}def Time_format (tiMESTR): Timestr = Timestr.replace (', ', ') #print timestr timelist = Timestr.split () #print timelist mon = " ". Join (Timelist[0]) #print mon timelist[0] = Monthdic[mon] #print timelist mytime =" ". Join (Timelist[2]) + '-' + "". Join (Timelist[0]) + '-' + ' ". Join (Timelist[1]) +" + "". Join (Timelist[3]) return mytimeif __name__ = ' __main__ ': Time str = ' Sep, 19:30 ' str = time_format (timestr) print str mytime = datetime.strptime (str, '%y-%m-%d %h:%m ') print mytime mytime = MyTime +timedelta (hours = 8) Print MyTime tdtime = DateTime.Now () print Tdtime if MyTime <= tdtime-timedelta (days = 7): print "too early"
Python Time processing