您好,登錄后才能下訂單哦!
獲取當(dāng)前時(shí)間戳
time_now = int(time.time()) #時(shí)間戳
# 1529461333
import time
current_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
current_hour=time.strftime('%H',time.localtime(time.time()))
#輸出格式: '2018-06-20 10:20:19'
current_time=time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(time.time()))
#在數(shù)據(jù)庫(kù)中,字段可以是varchar而不是datetime
a=1490931508
time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(a))
c='2017-03-31 11:38:28'
d=time.strptime(c,'%Y-%m-%d %H:%M:%S')
time.mktime(d)
from bson import json_util
import json
json.dumps(anObject, default=json_util.default)
json.loads(aJsonString, object_hook=json_util.object_hook)
方法一:
time1 = datetime.datetime.now()
time2 = datetime.datetime.now()
seconds = (time2 - time1).seconds
print 'seconds',seconds
方法二:
#先獲得時(shí)間數(shù)組格式的日期
oneDayAgo = (datetime.datetime.now() - datetime.timedelta(days = 1))
#minutes, days, months,
#轉(zhuǎn)換為時(shí)間戳:
timeStamp = int(time.mktime(oneDayAgo.timetuple()))
#轉(zhuǎn)換為其他字符串格式:
time1 = oneDayAgo.strftime("%Y-%m-%d %H:%M:%S")
time2 = host.update_time
if time2 > time1:
print "正常"
else:
print "未上報(bào)"
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。