我的代码-date
# coding: utf-8
# In[24]:
import time
import datetime
localtime = time.asctime( time.localtime(time.time()) )
last_fini_time = time.strftime("%y-%m-%d %H:%M:%S", time.localtime() )
fo = open("time.txt", "w")
fo.write(last_fini_time)
fo.close()
fo = open("time.txt", "r+")
last_fini_time = fo.read()
last_fini_time= last_fini_time[3:17]
last_fini_time
# In[32]:
localtime = time.asctime( time.localtime(time.time()) )
last_fini_time = time.strftime("%y-%m-%d %H:%M:%S", time.localtime() )
fo = open("time.txt", "w")
fo.write(last_fini_time)
fo.close()
fo = open("time.txt", "r+")
last_fini_time = fo.read()
last_fini_time= last_fini_time[3:17]
mth = last_fini_time[0:2]
day = last_fini_time[3:5]
hour = last_fini_time[6:8]
mins = last_fini_time[9:11]
print(last_fini_time,mth,day,hour,mins)
# In[25]:
localtime = time.asctime( time.localtime(time.time()) )
now = time.strftime("%y-%m-%d %H:%M:%S", time.localtime() )
now
# In[28]:
localtime = time.asctime( time.localtime(time.time()) )
now = time.strftime("%m-%d %H:%M:%S", time.localtime() )
now_time=datetime.datetime.strptime(now,'%m-%d %H:%M:%S')
lastfi_time = datetime.datetime.strptime(last_fini_time,'%m-%d %H:%M:%S')
delta= now_time - lastfi_time
print(delta)
# In[11]:
d1 = datetime.datetime.strptime('2015-03-05 17:41:20', '%Y-%m-%d %H:%M:%S')
d2 = datetime.datetime.strptime('2015-03-02 17:41:20', '%Y-%m-%d %H:%M:%S')
delta= d1 - d2
print(delta)
# In[6]: