我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用datetime.datetime.timetuple()。
def wait_time(self): """ If a rate limit error is encountered we will sleep until we can issue the API call again. refer https://github.com/ghostrong/weibo-crawler/blob/master/example.py """ try: rl = self.rate_limit() except Exception, e: rl = None if rl: if rl['remaining_ip_hits'] > 1 and rl['remaining_user_hits'] > 1: return 60 return rl['reset_time_in_seconds'] + 10 now = datetime.now() reset = now + timedelta(seconds=3600 - now.minute * 60 - now.second) reset_ts = time.mktime(datetime.timetuple(reset)) return reset_ts - time.time() + 60
def __updateHead(self): headT = self.font.get("head") if not headT: return general = self.config.get("General") style = self.config.get("Style") if general: version = general.get("version") createdTime = general.get("createdTime") modifiedTime = general.get("modifiedTime") if isinstance(version, float) or isinstance(version, int): headT.fontRevision = float(abs(version)) if isinstance(createdTime, datetime): headT.created = long(mktime(datetime.timetuple(createdTime)) - epoch_diff) if isinstance(modifiedTime, datetime): headT.modified = long(mktime(datetime.timetuple(modifiedTime)) - epoch_diff) self.font.recalcTimestamp = False if style: styleLink = style.get("styleLink") widthScale = style.get("widthScale") if styleLink in range(0, 5): # Clear related bits first headT.macStyle &= ~0b11 if styleLink == Constants.STYLELINK_BOLD: headT.macStyle |= 1 elif styleLink == Constants.STYLELINK_ITALIC: headT.macStyle |= 1<<1 elif styleLink == Constants.STYLELINK_BOLDITALIC: headT.macStyle |= 1 headT.macStyle |= 1<<1 else: pass if widthScale in range(1, 10): headT.macStyle &= ~(0b11<<5) if widthScale < 5: headT.macStyle |= 1<<5 elif widthScale > 5: headT.macStyle |= 1<<6 else: pass return
def painthms(self): self.canvas.delete(self._ALL) # delete the handles T = datetime.timetuple(datetime.utcnow()-self.delta) x,x,x,h,m,s,x,x,x = T self.root.title('%02i:%02i:%02i' %(h,m,s)) angle = pi/2 - pi/6 * (h + m/60.0) x, y = cos(angle)*0.70,sin(angle)*0.70 scl = self.canvas.create_line # draw the hour handle scl(self.T.windowToViewport(0,0,x,y), fill = self.timecolor, tag=self._ALL, width = self.pad/3) angle = pi/2 - pi/30 * (m + s/60.0) x, y = cos(angle)*0.90,sin(angle)*0.90 # draw the minute handle scl(self.T.windowToViewport(0,0,x,y), fill = self.timecolor, tag=self._ALL, width = self.pad/5) angle = pi/2 - pi/30 * s x, y = cos(angle)*0.95,sin(angle)*0.95 # draw the second handle scl(self.T.windowToViewport(0,0,x,y), fill = self.timecolor, tag=self._ALL, arrow = 'last') ## Draws a circle at a given point. # # @param x,y given point. #
def _encode(self, obj, ctx): return int(mktime(datetime.timetuple()))
def _encode(self, obj, ctx): unix_time = int(mktime(datetime.timetuple())) if unix_time == 0: return unix_time windows_time = unix_time + 11644473600 windows_time = windows_time * 10000000 return windows_time
def datetime_to_unixtime(datetime): return int(calendar.timegm(datetime.timetuple())) # Converts date string to unix UTC time
def to_xml(self, value): value = time.mktime(datetime.timetuple(value)) value = int(value) tpl = '<{name}>{value}</{name}>' return tpl.format(name=self.name, value=value)
def format_datetime(dt): now = time.mktime(dt.timetuple()) return formatdate(now)