Python datetime.datetime 模块,timetuple() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用datetime.datetime.timetuple()

项目:sfm-weibo-harvester    作者:gwu-libraries    | 项目源码 | 文件源码
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
项目:otRebuilder    作者:Pal3love    | 项目源码 | 文件源码
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
项目:code    作者:ActiveState    | 项目源码 | 文件源码
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.
    #
项目:sigpath    作者:utds3lab    | 项目源码 | 文件源码
def _encode(self, obj, ctx):
        return int(mktime(datetime.timetuple()))
项目:sigpath    作者:utds3lab    | 项目源码 | 文件源码
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
项目:amonone    作者:amonapp    | 项目源码 | 文件源码
def datetime_to_unixtime(datetime):
    return int(calendar.timegm(datetime.timetuple()))

# Converts date string to unix UTC time
项目:oejia_wx    作者:JoneXiong    | 项目源码 | 文件源码
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)
项目:uscensus    作者:nkrishnaswami    | 项目源码 | 文件源码
def format_datetime(dt):
        now = time.mktime(dt.timetuple())
        return formatdate(now)
项目:TornadoWeb    作者:VxCoder    | 项目源码 | 文件源码
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)