• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python time.localtime函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中time.time.localtime函数的典型用法代码示例。如果您正苦于以下问题:Python localtime函数的具体用法?Python localtime怎么用?Python localtime使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了localtime函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
开发者ID:CharlesZhong,项目名称:CnkiProject,代码行数:30,代码来源:CnkiParser.py


示例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()      
开发者ID:CharlesZhong,项目名称:CnkiProject,代码行数:29,代码来源:CnkiParser.py


示例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
开发者ID:libzz,项目名称:amiral,代码行数:26,代码来源:ccs_status.py


示例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))
开发者ID:fchypzero,项目名称:Instagram4sae,代码行数:10,代码来源:util.py


示例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))
开发者ID:fchypzero,项目名称:Instagram4sae,代码行数:15,代码来源:util.py


示例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
开发者ID:fchypzero,项目名称:Instagram4sae,代码行数:26,代码来源:util.py


示例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
开发者ID:guadalinex-archive,项目名称:acept,代码行数:25,代码来源:informe.py


示例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
开发者ID:abestick,项目名称:util,代码行数:28,代码来源:files.py


示例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
开发者ID:Huskyeder,项目名称:augustus,代码行数:47,代码来源:userMySQLInterface.py


示例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)
开发者ID:TVLuke,项目名称:FressenImPC,代码行数:9,代码来源:fressenimpc.py


示例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
开发者ID:joaojacome,项目名称:PagSeguroLib,代码行数:9,代码来源:PagSeguroHelper.py


示例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
开发者ID:libzz,项目名称:amiral,代码行数:44,代码来源:ccs_status.py


示例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])
开发者ID:Firef0x,项目名称:SublimeTextConfig,代码行数:10,代码来源:auto_file.py


示例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
开发者ID:schleichdi2,项目名称:OpenNfr_E2_Gui-5.3,代码行数:10,代码来源:twagenthelper.py


示例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() 
开发者ID:CharlesZhong,项目名称:CnkiProject,代码行数:11,代码来源:CnkiParser.py


示例16: insertPaper

 def insertPaper(self,paper):
     
     sql = "insert into  Paper(Expert_ID,Paper_ID,Paper_Title,Paper_Authorslist,Paper_Url,Paper_Origin,Paper_Pubtime,Paper_Database,Paper_Citation) values('%s','%s','%s','%s','%s','%s','%s','%s','%s')" %(paper.expertID,paper.paperID,paper.title,paper.authorsList,paper.url,paper.origin,paper.pubtime,paper.database,paper.citation)
     try:
         #print sql
         self.cursor.execute(sql)
     except Exception, e:
         f = open("PaperError.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() 
开发者ID:CharlesZhong,项目名称:CnkiProject,代码行数:12,代码来源:CnkiParser.py


示例17: procautoflush

	def procautoflush(self):
		view=self.view
		edit=self.edit
		curtime=time.strftime('%Y/%m/%d %H:%M:%S',time.localtime(time.time()))
		sel=view.sel()[0]
		reg=r"^>{3}[^>][\r\n\S\s]*?[^<]<{3}\d{4}/\d{2}/\d{2}\s\d{2}:\d{2}:\d{2}"
		reg_bb=view.find(reg,0)
		while not reg_bb.empty():
			if reg_bb.begin()<sel.begin() and reg_bb.end()>sel.end():
				treg=sublime.Region(reg_bb.end()-19,reg_bb.end())
				view.replace(edit,treg,curtime)
			reg_bb=view.find(reg,reg_bb.end())
开发者ID:Firef0x,项目名称:SublimeTextConfig,代码行数:12,代码来源:auto_file.py


示例18: SetTime

def SetTime():
	print "[VFD-GIGA] Set RTC time"
	import time
	if time.localtime().tm_isdst == 0:
		forsleep = 7200+time.timezone
	else:
		forsleep = 3600-time.timezone

	t_local = time.localtime(int(time.time()))
	print "set Gigabox RTC to %s (rtc_offset = %s sec.)" % (time.strftime("%Y/%m/%d %H:%M", t_local), forsleep)

	# Set RTC OFFSET (diff. between UTC and Local Time)
	try:		
		open("/proc/stb/fp/rtc_offset", "w").write(str(forsleep))
	except IOError:
		print "[VFD-GIGA] set RTC Offset failed!"

	# Set RTC
	try:		
		open("/proc/stb/fp/rtc", "w").write(str(int(time.time())))
	except IOError:
		print "[VFD-GIGA] set RTC time failed!"
开发者ID:shirehorse99,项目名称:oe-alliance-plugins,代码行数:22,代码来源:plugin.py


示例19: addDailyAction

    def addDailyAction(self, hour, minute, task, name):
        """Add an action to be run every day at a specific time.

		If a task with the given name is already registered with the
		scheduler, that task will be removed from the scheduling queue
		and registered anew as a periodic task.

		Can we make this addCalendarAction? What if we want to run
		something once a week? We probably don't need that for Webware,
		but this is a more generally useful module. This could be a
		difficult function, though. Particularly without mxDateTime.

		"""
        import time

        current = time.localtime(time.time())
        currHour = current[3]
        currMin = current[4]

        if hour > currHour:
            hourDifference = hour - currHour
            if minute > currMin:
                minuteDifference = minute - currMin
            elif minute < currMin:
                minuteDifference = 60 - currMin + minute
                hourDifference -= 1
            else:
                minuteDifference = 0
        elif hour < currHour:
            hourDifference = 24 - currHour + hour
            if minute > currMin:
                minuteDifference = minute - currMin
            elif minute < currMin:
                minuteDifference = 60 - currMin + minute
                hourDifference -= 1
            else:
                minuteDifference = 0
        else:
            if minute > currMin:
                hourDifference = 0
                minuteDifference = minute - currMin
            elif minute < currMin:
                minuteDifference = 60 - currMin + minute
                hourDifference = 23
            else:
                hourDifference = 0
                minuteDifference = 0

        delay = (minuteDifference + (hourDifference * 60)) * 60
        self.addPeriodicAction(time.time() + delay, 24 * 60 * 60, task, name)
开发者ID:akkmzack,项目名称:RIOS-8.5,代码行数:50,代码来源:Scheduler.py


示例20: __init__

 def __init__(self, month=None, day=None, year=None, epoch=None):
     import time
     if epoch is not None:
         (year, month, day, hour, mm, ss, ms, x, y) = time.localtime(epoch)
     else:
         if year is None:
             year = nowdict["year"]
         if day is None:
             day = nowdict["day"]
         if month is None:
             month = nowdict["month"]
         epoch = time.mktime( (year,month,day, 0, 0, 0, 0, 0, 0) )
     #print year, month, day, epoch, "<br>"
     self.year, self.month, self.day, self.epoch = year, month, day, epoch
开发者ID:AndyKovv,项目名称:hostel,代码行数:14,代码来源:htmldbhelpers.py



注:本文中的time.time.localtime函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python time.sleep函数代码示例发布时间:2022-05-27
下一篇:
Python time.clock函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap