當前位置: 首頁>>代碼示例>>Python>>正文


Python time.gmtime方法代碼示例

本文整理匯總了Python中time.gmtime方法的典型用法代碼示例。如果您正苦於以下問題:Python time.gmtime方法的具體用法?Python time.gmtime怎麽用?Python time.gmtime使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在time的用法示例。


在下文中一共展示了time.gmtime方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_use_modified_since

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def test_use_modified_since(app, static_file_directory, file_name):

    file_stat = os.stat(get_file_path(static_file_directory, file_name))
    modified_since = strftime(
        "%a, %d %b %Y %H:%M:%S GMT", gmtime(file_stat.st_mtime)
    )

    app.static(
        "/testing.file",
        get_file_path(static_file_directory, file_name),
        use_modified_since=True,
    )

    request, response = app.test_client.get(
        "/testing.file", headers={"If-Modified-Since": modified_since}
    )

    assert response.status == 304 
開發者ID:huge-success,項目名稱:sanic,代碼行數:20,代碼來源:test_static.py

示例2: formatTime

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def formatTime(self, record, datefmt=None):
        """
        Return the creation time of the specified LogRecord as formatted text.

        This method should be called from format() by a formatter which
        wants to make use of a formatted time. This method can be overridden
        in formatters to provide for any specific requirement, but the
        basic behaviour is as follows: if datefmt (a string) is specified,
        it is used with time.strftime() to format the creation time of the
        record. Otherwise, the ISO8601 format is used. The resulting
        string is returned. This function uses a user-configurable function
        to convert the creation time to a tuple. By default, time.localtime()
        is used; to change this for a particular formatter instance, set the
        'converter' attribute to a function with the same signature as
        time.localtime() or time.gmtime(). To change it for all formatters,
        for example if you want all logging times to be shown in GMT,
        set the 'converter' attribute in the Formatter class.
        """
        ct = self.converter(record.created)
        if datefmt:
            s = time.strftime(datefmt, ct)
        else:
            t = time.strftime(self.default_time_format, ct)
            s = self.default_msec_format % (t, record.msecs)
        return s 
開發者ID:war-and-code,項目名稱:jawfish,代碼行數:27,代碼來源:__init__.py

示例3: make_msgid

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def make_msgid(idstring=None, domain=None):
    """Returns a string suitable for RFC 2822 compliant Message-ID, e.g:

    <20020201195627.33539.96671@nightshade.la.mastaler.com>

    Optional idstring if given is a string used to strengthen the
    uniqueness of the message id.  Optional domain if given provides the
    portion of the message id after the '@'.  It defaults to the locally
    defined hostname.
    """
    timeval = time.time()
    utcdate = time.strftime('%Y%m%d%H%M%S', time.gmtime(timeval))
    pid = os.getpid()
    randint = random.randrange(100000)
    if idstring is None:
        idstring = ''
    else:
        idstring = '.' + idstring
    if domain is None:
        domain = socket.getfqdn()
    msgid = '<%s.%s.%s%s@%s>' % (utcdate, pid, randint, idstring, domain)
    return msgid 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:24,代碼來源:utils.py

示例4: utcfromtimestamp

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def utcfromtimestamp(cls, t):
        "Construct a UTC datetime from a POSIX timestamp (like time.time())."
        t, frac = divmod(t, 1.0)
        us = int(frac * 1e6)

        # If timestamp is less than one microsecond smaller than a
        # full second, us can be rounded up to 1000000.  In this case,
        # roll over to seconds, otherwise, ValueError is raised
        # by the constructor.
        if us == 1000000:
            t += 1
            us = 0
        y, m, d, hh, mm, ss, weekday, jday, dst = _time.gmtime(t)
        ss = min(ss, 59)    # clamp out leap seconds if the platform has them
        return cls(y, m, d, hh, mm, ss, us)

    # XXX This is supposed to do better than we *can* do by using time.time(),
    # XXX if the platform supports a more accurate way.  The C implementation
    # XXX uses gettimeofday on platforms that have it, but that isn't
    # XXX available from Python.  So now() may return different results
    # XXX across the implementations. 
開發者ID:Soft8Soft,項目名稱:verge3d-blender-addon,代碼行數:23,代碼來源:datetime.py

示例5: on_epoch_end

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def on_epoch_end(self, epoch, logs={}):
        '''
        At the end of each epoch we
          1. create a directory to checkpoint data
          2. save the arguments used to initialise the run
          3. generate N sentences in the val data by sampling from the model
          4. calculate metric score of the generated sentences
          5. determine whether to stop training and sys.exit(0)
          6. save the model parameters using BLEU
        '''
        savetime = strftime("%d%m%Y-%H%M%S", gmtime())
        path = self.create_checkpoint_directory(savetime)
        self.save_run_arguments(path)

        # Generate training and val sentences to check for overfitting
        self.generate_sentences(path)
        meteor, bleu, ter = self.multeval_scores(path)
        val_loss = logs.get('val_loss')

        self.early_stop_decision(len(self.val_metric)+1, meteor, val_loss)
        self.checkpoint_parameters(epoch, logs, path, meteor, val_loss)
        self.log_performance() 
開發者ID:elliottd,項目名稱:GroundedTranslation,代碼行數:24,代碼來源:Callbacks.py

示例6: format_timestamp

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def format_timestamp(ts):
    """Formats a timestamp in the format used by HTTP.

    The argument may be a numeric timestamp as returned by `time.time`,
    a time tuple as returned by `time.gmtime`, or a `datetime.datetime`
    object.

    >>> format_timestamp(1359312200)
    'Sun, 27 Jan 2013 18:43:20 GMT'
    """
    if isinstance(ts, numbers.Real):
        pass
    elif isinstance(ts, (tuple, time.struct_time)):
        ts = calendar.timegm(ts)
    elif isinstance(ts, datetime.datetime):
        ts = calendar.timegm(ts.utctimetuple())
    else:
        raise TypeError("unknown timestamp type: %r" % ts)
    return email.utils.formatdate(ts, usegmt=True) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:21,代碼來源:httputil.py

示例7: create_safe_file_name

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def create_safe_file_name(self,file_name):
        """
        Using a given file name
        create a new file name that is unique
        so collisions do not occur.
        """

        if not file_name:
            return(None)

        file_pieces = file_name.split(".")
        file_base = file_pieces[0]
        file_ext = ".".join(file_pieces[1:])
        current_time = time.strftime("%Y_%m_%d_%H_%M_%S",time.gmtime())
        new_file_name = file_base + "_" + current_time + "." + file_ext

        if os.path.exists(new_file_name):
            print(" ".join(["ERROR!\tCan not find a safe file name, ",
                            "the file to be written already exists. ",
                            "Please move or rename the file:",
                            os.path.abspath(new_file_name)]))
            return(None)
        return(new_file_name) 
開發者ID:broadinstitute,項目名稱:single_cell_portal,代碼行數:25,代碼來源:PortalFiles.py

示例8: _TIMESTAMP_NTZ_to_python

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def _TIMESTAMP_NTZ_to_python(self, ctx):
        """Converts TIMESTAMP NTZ to Snowflake Formatted String.

        No timezone info is attached.
        """
        def conv(value):
            microseconds, fraction_of_nanoseconds = \
                _extract_timestamp(value, ctx)
            try:
                t = time.gmtime(microseconds)
            except (OSError, ValueError) as e:
                logger.debug(
                    "OSError occurred but falling back to datetime: %s", e)
                t = ZERO_EPOCH + timedelta(seconds=(microseconds))
            return format_sftimestamp(ctx, t, fraction_of_nanoseconds)

        return conv 
開發者ID:snowflakedb,項目名稱:snowflake-connector-python,代碼行數:19,代碼來源:converter_snowsql.py

示例9: locale_date

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def locale_date(v):
    return time.strftime('%c', time.gmtime(v)) 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:4,代碼來源:cpstats.py

示例10: iso_format

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def iso_format(v):
    return time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(v)) 
開發者ID:cherrypy,項目名稱:cherrypy,代碼行數:4,代碼來源:cpstats.py

示例11: step

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def step(self, amt=1):
        z = calendar.timegm(time.gmtime(time.time()))

        for i in range(32):
            color = self.palette((z & (1 << i)) > 0)
            if self._reverse:
                i = 31 - i

            start = (self._bitSpace + self._bitWidth) * i
            self.layout.fill(color, start, start + self._bitWidth) 
開發者ID:ManiacalLabs,項目名稱:BiblioPixelAnimations,代碼行數:12,代碼來源:BinaryEpochClock.py

示例12: get_sql_query_time

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def get_sql_query_time(timestamp, timestamp_format):
    if timestamp_format == Constant.NONE:
        return str(timestamp)
    else:
        return "\'" + time.strftime(timestamp_format, time.gmtime(timestamp / 1000.0)) + "\'" 
開發者ID:insightfinder,項目名稱:InsightAgent,代碼行數:7,代碼來源:getlogs_mysql.py

示例13: __init__

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def __init__(self, createTime=time.gmtime()):
        self.createTime = createTime
        self.username = ''
        self.cookie = ''
        self.tlist = [] 
開發者ID:xypnox,項目名稱:todxpy,代碼行數:7,代碼來源:fabric.py

示例14: Run

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def Run(self):
    duration = int(self._args[0])
    converted_time = time.strftime('%H:%M:%S', time.gmtime(duration))

    if len(self._args) > 1:
      logging.info('Sleeping for %s (%s).', converted_time, str(self._args[1]))
    else:
      logging.info('Sleeping for %s before continuing...', converted_time)
    time.sleep(duration) 
開發者ID:google,項目名稱:glazier,代碼行數:11,代碼來源:installer.py

示例15: ftime

# 需要導入模塊: import time [as 別名]
# 或者: from time import gmtime [as 別名]
def ftime(self, base = None):
        if base != None:
            realt = base.realt - (base.monot - self.monot)
        else:
            realt = self.realt
        return strftime('%Y-%m-%d %H:%M:%S+00', gmtime(round(realt))) 
開發者ID:sippy,項目名稱:rtp_cluster,代碼行數:8,代碼來源:MonoTime.py


注:本文中的time.gmtime方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。