获取当前时间戳
time_now = int(time.time()) #时间戳
# 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()))
#在数据库中,字段可以是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
方法二:
#先获得时间数组格式的日期
oneDayAgo = (datetime.datetime.now() - datetime.timedelta(days = 1))
#minutes, days, months,
#转换为时间戳:
timeStamp = int(time.mktime(oneDayAgo.timetuple()))
#转换为其他字符串格式:
time1 = oneDayAgo.strftime("%Y-%m-%d %H:%M:%S")
time2 = host.update_time
if time2 > time1:
print "正常"
else:
print "未上报"
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。