本文整理汇总了Python中time.time.strftime函数的典型用法代码示例。如果您正苦于以下问题:Python strftime函数的具体用法?Python strftime怎么用?Python strftime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了strftime函数的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: Update
def Update(self):
saat = str(config.plugins.TimeSet.UTCTim.value[0])
if len(saat) < 2:
saat = '0' + saat
minuti = str(config.plugins.TimeSet.UTCTim.value[1])
if len(minuti) < 2:
minuti = '0' + minuti
sekunde = strftime('%S', localtime())
pp = config.plugins.TimeSet.NDate.value
import time
TimeString = time.strftime('%Y%m%d', time.gmtime(pp)) + saat + minuti + sekunde
RTCString = time.strftime('%Y.%m.%d', time.gmtime(pp)) + '-' + saat + ':' + minuti + ':' + sekunde
TimeZoneS = config.timezone.val.value
ipos1 = TimeZoneS.find('(GMT')
ipos2 = TimeZoneS.find(')')
tmp = TimeZoneS[ipos1 + 4:ipos2]
if len(tmp) == 0:
tmp = '+00'
tzpredznak = tmp[:1]
tzvalue = str(int(tmp[1:3]))
TimeString = TimeString + tzpredznak + tzvalue
import os as os
cmd = 'echo "' + str(TimeString) + '" > /proc/settime'
os.system(cmd)
cmd = 'date -u -s "' + str(RTCString) + '"'
os.system(cmd)
self.session.openWithCallback(self.callback, MessageBox, _('RTC Update done! \n\nGUI Clock Update done!'), type = 1, timeout = 5)
示例5: 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))
示例6: 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])
示例7: Page
def Page(self):
plugin_path = '/usr/lib/enigma2/python/RTiTeam/TimeSet'
print plugin_path
before = 'Before: Local=' + strftime('%H:%M', localtime()) + ', UTC=' + strftime('%H:%M', gmtime())
cmd = str(plugin_path + '/ntpdate -t 20 0.debian.pool.ntp.org')
res = popen(cmd).read()
if res == '':
cmd = 'ls -l %s%s' % (plugin_path, '/ntpdate')
res = popen(cmd).read()
if res[3] != 'x':
cmd = 'chmod 755 %s%s' % (plugin_path, '/ntpdate')
res = popen(cmd).read()
self.session.open(MessageBox, _('ntpdate problem: attributes for ntpdate have not been correct! Fixed now! Try again!\n%s' % res), MessageBox.TYPE_INFO)
else:
self.session.open(MessageBox, _('ntpdate problem: Internet connection ok? Time server ok?'), MessageBox.TYPE_INFO)
else:
z1 = mktime(datetime.utcnow().timetuple())
config.plugins.TimeSet.NDate = ConfigDateTime(default = z1, formatstring = _('%d.%B %Y'), increment = 86400)
config.plugins.TimeSet.UTCTim = ConfigClock(default = z1)
self.list1 = []
self.list1.append(getConfigListEntry(_('UTC Time'), config.plugins.TimeSet.UTCTim))
self.list1.append(getConfigListEntry(_('Date'), config.plugins.TimeSet.NDate))
self['config'].setList(self.list1)
self.selectionChanged()
saat = str(config.plugins.TimeSet.UTCTim.value[0])
if len(saat) < 2:
saat = '0' + saat
minuti = str(config.plugins.TimeSet.UTCTim.value[1])
if len(minuti) < 2:
minuti = '0' + minuti
sekunde = strftime('%S', localtime())
pp = config.plugins.TimeSet.NDate.value
import time
TimeString = time.strftime('%Y%m%d', time.gmtime(pp)) + saat + minuti + sekunde
RTCString = time.strftime('%Y.%m.%d', time.gmtime(pp)) + '-' + saat + ':' + minuti + ':' + sekunde
TimeZoneS = config.timezone.val.value
ipos1 = TimeZoneS.find('(GMT')
ipos2 = TimeZoneS.find(')')
tmp = TimeZoneS[ipos1 + 4:ipos2]
if len(tmp) == 0:
tmp = '+00'
tzpredznak = tmp[:1]
tzvalue = str(int(tmp[1:3]))
TimeString = TimeString + tzpredznak + tzvalue
import os
cmd = 'echo "' + str(TimeString) + '" > /proc/settime'
os.system(cmd)
cmd = 'date -u -s "' + str(RTCString) + '"'
os.system(cmd)
self.session.openWithCallback(self.callback, MessageBox, _('RTC Update done! \n\nGUI Clock Update done!\n\n' + before + '\n\nntpdate done! ' + res + '\nAfter: Local=' + strftime('%H:%M', localtime()) + ', UTC=' + strftime('%H:%M', gmtime())), type = 1, timeout = 15)
示例8: getFormattedDate
def getFormattedDate(self, dt):
"""
returns a formatted date string
@summary: returns either the formatted datestring defined by DATE_FORMAT_STRING or it defaults to '%Y-%m-%d %H:%M:%S'.
@type dt: datetime
@param dt: datetime object to format
@rtype: string
@return: formatted date string
"""
if DATE_FORMAT_STRING == '':
return time.strftime('%Y-%m-%d %H:%M:%S', dt.timetuple())
else:
return time.strftime(DATE_FORMAT_STRING, dt.timetuple())
示例9: 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
示例10: wrapper
def wrapper(*args, **kargs):
t1 = time.time()
res = func(*args, **kargs)
tel = time.time()-t1
timeformated = time.strftime( "%H:%M:%S",time.gmtime(tel))
print '-'*5 + '%s took %0.3f ms' % (func.func_name + str(kargs) + str(args), (tel)*1000.0) + '|' + timeformated + '|'+ '-'*10
return res
示例11: create_temporary_path
def create_temporary_path(self):
import time
from sct_utils import slash_at_the_end
path_tmp = slash_at_the_end("tmp." + time.strftime("%y%m%d%H%M%S"), 1)
sct.run("mkdir " + path_tmp, self.verbose)
return path_tmp
示例12: selectionChanged
def selectionChanged(self):
self['introduction'].setText(_('Your time = UTC Time + Your Time Zone'))
self['vreme'].setText(_('*Current Your Time: ' + str(datetime.now().strftime('%H:%M:%S'))))
saat = str(config.plugins.TimeSet.UTCTim.value[0])
if len(saat) < 2:
saat = '0' + saat
minuti = str(config.plugins.TimeSet.UTCTim.value[1])
if len(minuti) < 2:
minuti = '0' + minuti
sekunde = strftime('%S', localtime())
pp = config.plugins.TimeSet.NDate.value
import time
TimeString = time.strftime('%Y%m%d', time.gmtime(pp)) + saat + minuti + sekunde
TimeZoneS = config.timezone.val.value
ipos1 = TimeZoneS.find('(GMT')
ipos2 = TimeZoneS.find(')')
tmp = TimeZoneS[ipos1 + 4:ipos2]
if len(tmp) == 0:
tmp = '+00'
tzpredznak = tmp[:1]
tzvalue = str(int(tmp[1:3]))
TimeString = TimeString + tzpredznak + tzvalue
self['timez'].setText(_('Time Zone : ' + str(TimeZoneS)))
self['poraka'].setText(_('TimeString : ' + str(TimeString)))
novovreme = str(int(saat) + int(tzpredznak + tzvalue))
if len(novovreme) < 2:
novovreme = '0' + novovreme
novovreme = novovreme + ':' + minuti
self['vreme'].setText(_('Your Time (After Setting): ' + str(novovreme)))
示例13: run
def run(self):
t0 = (2013, 3, 26, 23, 0, 0, 0, 1, -1)
t0 = calendar.timegm(t0)
t1 = time.time()
announcement_frequency = 60*60
if t1 - self.last_run < announcement_frequency:
return
print 't1 - self.last_run:',t1 - self.last_run
print 'self.last_run:',self.last_run
self.last_run = int(t1- (int(t1) % announcement_frequency))
t = int(t1 - t0)
days = t // (3600 * 24)
#move it back one day
days -= 1
date = time.gmtime(t0 + (days * (3600 * 24)))
next_date = time.gmtime(t0 + ((days+1) * (3600 * 24)))
response = 'NOTICE: Sefira for \x031,9YESTERDAY\x03, {date}: *{count}* Days of the omer.' \
+ ' You can count until sunset on {next_date}.' \
+ ' WARNING: THIS IS ALPHA, DOUBLE CHECK THIS YOURSELF (http://goo.gl/hzY2v)'
response = response.format(date=time.strftime("%a NIGHT, %d %b %I:%M %p",date),
next_date=time.strftime("%a",next_date),
count=(days+1))
for bot in self.bot_factory.bots:
bot.msg(bot.factory.channel, response)
示例14: backup_db
def backup_db(self):
'''Backup/archive esget.db'''
arcname = os.path.join(self.dbarchivedir,
os.path.split(self.dbname)[1] +
"."+time.strftime("%Y-%m-%d_%H-%M"))
shutil.copy(self.dbname, arcname)
self._log.info("Archived {0}".format(self.dbname))
return()
示例15: hoy_mun
def hoy_mun(cod,name):
import datetime
import time
import json
#Conexion BBDD
conexion = conexion_bbdd()
db = conexion.othesoluciones1
#Redireccion en la paginacion de la pagina de reportes
if (cod=='reporte'):
return reporte(name)
#Busqueda de datos en coleccion: prediccionesAEMET
collection1 = db.prediccionesAEMET
print elimina_tildes(name.decode('utf-8'))
name2 = elimina_tildes(name.decode('utf-8'))
print name2
print cod
cursorHoyM1 = collection1.find_one({"Municipio": name2})
print time.strftime("%Y-%m-%d")
busquedaAEMET = cursorHoyM1[time.strftime("%Y-%m-%d")]
#Carga de imagenes del municipio
collection2 = db.imagenes
cursorHoyM2 = collection2.find_one({'municipio':name2})
print cursorHoyM2['filename_img_municipio']
print cursorHoyM2['filename_img_municipio_cam']
f1 = gridfs.GridFS(db,"images").get_version(cursorHoyM2['filename_img_municipio'])
plot_url_img = base64.b64encode(f1.read())
f2 = gridfs.GridFS(db,"images").get_version(cursorHoyM2['filename_img_municipio_cam'])
plot_url_img_cam = base64.b64encode(f2.read())
#Busqueda de datos en coleccion:calidad_aire_por_municipio
collection3= db.calidad_aire_por_municipio
cursor3 = collection3.find_one({'Municipio':name2})
#Carga de las noticias del dia
noticias_del_dia=cargaNoticias()
#Conexion BBDD
conexion.close()
return template("views/p_hoy_mun.tpl",name=name, busquedaAEMET=busquedaAEMET,plot_url_img=plot_url_img, plot_url_img_cam=plot_url_img_cam, noticias_del_dia=noticias_del_dia, cursor3=cursor3)