本文整理汇总了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
示例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
示例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
示例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.
示例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()
示例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)
示例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)
示例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
示例9: locale_date
# 需要导入模块: import time [as 别名]
# 或者: from time import gmtime [as 别名]
def locale_date(v):
return time.strftime('%c', time.gmtime(v))
示例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))
示例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)
示例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)) + "\'"
示例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 = []
示例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)
示例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)))