import re,time
from datetime import timedelta,datetime
list=[u'10分鐘前',u'2小時前',u'22小時前',u'昨天 14:55',u'08-18',u'tue jun 12 15:49:08 +0800 2018',u'剛剛']
for i in list:
if '分鐘前' in i.encode('utf-8'):
a=re.findall('(.*?)分鐘前', i.encode('utf-8'))[0]
ll=(datetime.now()-timedelta(minutes=int(str(a)))).strftime('%y/%m/%d/%h/%m')
print('幾分鐘前'+ll)
elif '小時前' in i.encode('utf-8'):
a = re.findall('(.*?)小時前', i.encode('utf-8'))[0]
ll = (datetime.now() - timedelta(hours=int(str(a)))).strftime('%y/%m/%d/%h/%m')
print('幾小時前'+ll)
elif '昨天' in i.encode('utf-8'):
ll = str(time.strftime('%y/'))+(datetime.now() - timedelta(days=int(str(1)))).strftime('%m/%d/')+str(i.encode('utf-8').replace('昨天 ','').replace(':','/'))
print('昨天'+ll)
elif '剛剛' in i.encode('utf-8'):
ll=time.strftime('%y/%m/%d/%h/%m')
print('剛剛'+str(ll))
elif '-' in i.encode('utf-8'):
ll=str(time.strftime('%y/'))+i.replace('-','/')+str(time.strftime('/%h/%m'))
print('具體日期'+str(ll))
elif '+0800' in i.encode('utf-8'):
s = time.strptime(i.encode('utf-8'), '%a %b %d %h:%m:%s +0800 %y')
ll= time.strftime('%y/%m/%d/%h/%m', s)
print(ll)
else:
print(i)
如有不恰當處,請指出 謝謝 ios 對時間排序
排序 對時間進行排序 nsmutablearray dataarray nsmutablearray alloc initwithcapacity 0 nsmutabledictionary dir nsmutabledictionary alloc init dir setobject 2012 ...
Jquery對時間進行判斷,格式化
1.獲取當前時間,並進行格式化 var mydate new date 獲取當前年 var year mydate.getfullyear 獲取當前月 var month mydate.getmonth 1 獲取當前日 var date mydate.getdate var h mydate.get...
對時間的封裝util
將乙個秒數的時間轉成形如00 00 00字串 public static string parsetime string date else else if integer.parseint curday integer.parseint day 2 else else else return da...