本文整理汇总了Python中time.time.localtime函数的典型用法代码示例。如果您正苦于以下问题:Python localtime函数的具体用法?Python localtime怎么用?Python localtime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了localtime函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: InsertKeyWordToDB
def InsertKeyWordToDB(fromSubDir,toSubDir):
db = DB()
parser = Parser()
for index in range(fromSubDir,toSubDir):
for root,dirs,files in os.walk('test/keyword/'+str(index)+"/"):
#each subdir: 1000record
start = time.time()
for afile in files:
if afile == '.DS_Store':
continue
words = afile.split('_')
aExpert = Expert(words[0].strip(),words[1].strip(),words[2].replace(".html","").strip())
aExpert.setKeyword(parser.parseKeyword(root,afile))
aExpert.ChangeKeywordsToString()
#print aExpert.keywordsList
if not db.isExpertExist(aExpert):
db.insertExpert(aExpert)
end = time.time()
db.conn.commit()
print ("KeywordSubDir %d is Done!"%index),
print time.strftime('%m-%d %H:%M:%S',time.localtime(time.time())),"total:",end-start
f = open("KeywordsToDB.log","a")
f.write(time.strftime('%m-%d %H:%M:%S',time.localtime(time.time()))+" keywordSubDir"+str(index)+" is Done! "+"total"+str(end-start) )
f.close()
db.close()
示例2: InsertPaperToDB
def InsertPaperToDB(fromSubDir,toSubDir):
db = DB()
parser = Parser()
for index in range(fromSubDir,toSubDir):
for root,dirs,files in os.walk('test/paper/'+str(index)+"/"):
n = 1000*index
start = time.time()
for afile in files:
if afile == '.DS_Store':
continue
words = afile.split('_')
papers = (parser.parsePaper(root,afile))
for eachPapaer in papers:
if not db.isPaperExist(eachPapaer):
db.insertPaper(eachPapaer)
print "n:",n,
print "Expert_ID %s is done"%words[0]
n = n + 1
db.conn.commit()
end = time.time()
print ("PaperSubDir %d is Done!"%index),
print time.strftime('%m-%d %H:%M:%S',time.localtime(time.time())),"time:",end-start,
f = open("PaperToDB.log","a")
f.write(time.strftime('%m-%d %H:%M:%S',time.localtime(time.time()))+" paperSubDir"+str(index)+" is Done! "+"total"+str(end-start) )
f.close()
db.close()
示例3: getStatus
def getStatus(session_id, host_id):
"""Returns a dictionary describing the status of the host"""
# Get some basic info
hostname = getHostName(session_id, host_id)
hoststatus = getHostStatus(hostname)
# Get the host's CFengine status
status = getCfengineHostStatus(session_id, hoststatus.host._properties)
# Get state information
status["reachable"] = hoststatus.reachable
status["operating_rev"] = hoststatus.operatingRevision
status["operating_rev_status"] = hoststatus.operatingRevisionStatus
status["operating_rev_text"] = hoststatus.operatingRevisionText
status["operating_rev_hint"] = hoststatus.operatingRevisionHint
status["active_rev"] = hoststatus.activeRevision
status["generated_rev"] = hoststatus.generatedRevision
status["current_load"] = hoststatus.currentLoad
status["uptime"] = hoststatus.uptime
status["infoUpdatedAt"] = time.strftime("%d/%m/%Y %H:%M:%S", \
time.localtime(hoststatus.infoUpdatedAt))
status["lastCheckedAt"] = time.strftime("%d/%m/%Y %H:%M:%S", \
time.localtime(hoststatus.lastCheckedAt))
return status
示例4: friendtime
def friendtime(dt,format='%Y-%m-%d %H:%M'):
'''时间友好显示化'''
t = time.localtime(time.time())
today = time.mktime(time.strptime(time.strftime('%Y-%m-%d 00:00:00', t),'%Y-%m-%d %H:%M:%S'))
yestoday = today - 3600*24
if dt > today:
return u'今天' + time.strftime('%H:%M',time.localtime(dt))
if dt > yestoday and dt < today:
return u'昨天' + time.strftime('%H:%M',time.localtime(dt))
return time.strftime(format,time.localtime(dt))
示例5: formattime
def formattime(dt,format='%Y-%m-%d %H:%M'):
mins = int(time.time())-dt
if mins < 60:
return u'%s 秒前' % mins
elif mins < 3600:
return u'%s 分钟前' % (mins / 60)
elif mins < 24*3600:
return u'%s 小时前' % (mins/3600)
elif mins < 3*24*3600:
return u'%s 天前' % (mins/(3600*24))
_time = time.localtime(dt)
_now = time.localtime(time.time())
if _time.tm_year == _now.tm_year:
format='%m-%d %H:%M'
return time.strftime(format,time.localtime(dt))
示例6: getTime
def getTime(daterange=1):
'''获取指定时间戳'''
t = time.localtime(time.time())
t = list(t)
t[3] = t[4] = t[5] = 0
date = 0
if daterange == 1: #当天
t[3] = t[4] = t[5] = 0
date = time.mktime(tuple(t))
elif daterange == 2: #本周
t[2] -= t[6]
date = time.mktime(tuple(t))
elif daterange == 3: #本月
t[2] = 1
date = time.mktime(tuple(t))
elif daterange == 4: #昨天
t[2] = t[2] - 1
date = time.mktime(tuple(t))
elif daterange == 5: #前天
t[2] = t[2] - 2
date = time.mktime(tuple(t))
else:
return 0
date = int(date)
return date
示例7: ind_horario
def ind_horario(self, horario):
import time
# se consulta horario de dia actual
dweek = time.strftime("%a", time.localtime())
dsem = dweek[0:2].capitalize()
if dsem.find("Lu") != -1 or dsem.find("Mo") != -1:
ind = horario.find("Mo")
elif dsem.find("Ma") != -1 or dsem.find("Tu") != -1:
ind = horario.find("Tu")
elif dsem.find("Mi") != -1 or dsem.find("We") != -1:
ind = horario.find("We")
elif dsem.find("Ju") != -1 or dsem.find("Th") != -1:
ind = horario.find("Th")
elif dsem.find("Vi") != -1 or dsem.find("Fr") != -1:
ind = horario.find("Fr")
elif dsem.find("Sa") != -1 or dsem.find("Sa") != -1:
ind = horario.find("Sa")
elif dsem.find("Do") != -1 or dsem.find("Su") != -1:
ind = horario.find("Su")
else:
ind = -1
return ind
示例8: datestring
def datestring(t=None,sec=False):
"""
Datestring
Inputs:
(optional)
t - time.localtime()
sec - bool - whether to include sec [SS] in output
Outputs:
ds - str - date in YYYYMMDD-HHMM[SS] format
by Sam Burden 2012
"""
if t is None:
import time
t = time.localtime()
ye = '%04d'%t.tm_year
mo = '%02d'%t.tm_mon
da = '%02d'%t.tm_mday
ho = '%02d'%t.tm_hour
mi = '%02d'%t.tm_min
se = '%02d'%t.tm_sec
if not sec:
se = ''
return ye+mo+da+'-'+ho+mi+se
示例9: fillModels
def fillModels(cv,mname,fname,comment=None):
import os
import time
import stat
if (comment==None):
comment=" "
pmmlfile=file(fname)
sql='SELECT CURDATE()'
cv.execute(sql)
date=cv.fetchone()[0]
atime=os.stat(fname)[stat.ST_ATIME]
atime=time.asctime(time.localtime(atime))
ctime=os.stat(fname)[stat.ST_CTIME]
ctime=time.asctime(time.localtime(ctime))
mtime=os.stat(fname)[stat.ST_MTIME]
mtime=time.asctime(time.localtime(mtime))
mode=os.stat(fname)[stat.ST_MODE]
mode=oct(mode & 0777)
# we were using the mysql specific LOAD_FILE, but it
# wasn't working in Korea, so we're doing the file load
# the hard way
load_file = file (fname, "rb")
file_content = load_file.read ()
load_file.close ()
sql="INSERT INTO models VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)"
try:
login=getlogin()
except:
login='NULL';
cv.execute (sql,
( mname \
, file_content \
, comment \
, str(os.getuid()) \
, login \
, str(os.getgid()) \
, atime \
, mtime \
, ctime \
, str(mode) \
))
return
示例10: daybeforehollyday
def daybeforehollyday(d):
#get the epoch from current date object
x = time.mktime(d);
#add 86400 seconds (one day)
x=x+86400
#create a struct time object from that
d2 = time.localtime(x)
#check if that date is a weekend
return isHollyday(d2)
示例11: formatDate
def formatDate(cls, date):
_format = "%Y-%m-%d\T%H:%M:%S"
if isinstance(date, datetime):
d = date.strftime(_format)
elif isinstance(date, int):
d = datetime.strptime(time.localtime(date), _format)
else:
d = date
return d
示例12: getHostStatusSummary
def getHostStatusSummary(session_id, host_name):
"""Returns an overall status for the host"""
status = {}
try:
hoststatus = getHostStatus(host_name)
except:
status = {"status":STATUS_UNKNOWN,"status_text":"UNKNOWN", \
"status_hint":"No status information available"}
return status
status["infoUpdatedAt"] = time.strftime("%d/%m/%Y %H:%M:%S", \
time.localtime(hoststatus.infoUpdatedAt))
status["lastCheckedAt"] = time.strftime("%d/%m/%Y %H:%M:%S", \
time.localtime(hoststatus.lastCheckedAt))
status["status"] = STATUS_OK
status["status_text"] = "UP"
status["status_hint"] = "Last checked at %s" % status["lastCheckedAt"]
if not hoststatus.reachable:
status["status"] = STATUS_CRITICAL
status["status_text"] = "Down"
status["status_hint"] = "Not seen since %s" % status["infoUpdatedAt"]
return status
if hoststatus.operatingRevisionStatus != STATUS_OK:
status["status"] = hoststatus.operatingRevisionStatus
status["status_text"] = hoststatus.operatingRevisionText
status["statux_hint"] = hoststatus.operatingRevisionHint
return status
cstatus = getCfengineHostStatus(session_id, hoststatus.host._properties)
if cstatus["ssh_key_status"] != STATUS_OK:
status["status"] = cstatus["ssh_key_status"]
status["status_text"] = "SSH Key Error"
status["status_hint"] = cstatus["ssh_key_text"]
return status
if cstatus["cfengine_key_status"] != STATUS_OK:
status["status"] = cstatus["cfengine_key_status"]
status["status_text"] = "CFengine Key Error"
status["status_hint"] = cstatus["cfengine_key_text"]
return status
return status
示例13: procdt
def procdt(self,args=None):
view=self.view
edit=self.edit
dicdt={'dt':'TM_TH_DTTM','date':'TM_TH_DATE','time':'TM_TH_TIME'}
ctime=time.localtime(time.time())
dicvl={'dt':time.strftime('%Y/%m/%d %H:%M:%S',ctime),'date':time.strftime('%Y/%m/%d',ctime),'time':time.strftime('%H/%M/%S',ctime)}
if not args==None:
mcdt='#'+dicdt[args]
reg_bb=view.find(mcdt,0)
view.replace(edit, reg_bb, dicvl[args])
示例14: d_print
def d_print(*args):
import time
if MDEBUG:
if MDEBUG_TIMESTAMP:
s = '%s - ' % time.strftime('%H:%M:%S',time.localtime())
else:
s = ''
for arg in args:
s += str(arg)
print s
示例15: insertExpert
def insertExpert(self,expert):
sql = "insert into GeniusExpert(Expert_ID,Expert_name,Expert_keywords) values('%s','%s','%s')" %(expert.expertID,expert.name,str(expert.keywordsList))
try:
#print sql
self.cursor.execute(sql)
except Exception, e:
f = open("ExpertError.log","a")
f.write(str(e)+"\n")
f.write(sql+"\n")
f.write(time.strftime('%m-%d %H:%M:%S',time.localtime(time.time())))
f.close()