本文整理汇总了Python中datetime.html方法的典型用法代码示例。如果您正苦于以下问题:Python datetime.html方法的具体用法?Python datetime.html怎么用?Python datetime.html使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datetime
的用法示例。
在下文中一共展示了datetime.html方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: total_seconds
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def total_seconds(delta):
"""
Returns the total seconds in a ``datetime.timedelta``.
Python 2.6 does not have ``timedelta.total_seconds()``, so we have
to calculate this ourselves. On 2.7 or better, we'll take advantage of the
built-in method.
The math was pulled from the ``datetime`` docs
(http://docs.python.org/2.7/library/datetime.html#datetime.timedelta.total_seconds).
:param delta: The timedelta object
:type delta: ``datetime.timedelta``
"""
if sys.version_info[:2] != (2, 6):
return delta.total_seconds()
day_in_seconds = delta.days * 24 * 3600.0
micro_in_seconds = delta.microseconds / 10.0**6
return day_in_seconds + delta.seconds + micro_in_seconds
# Checks to see if md5 is available on this system. A given system might not
# have access to it for various reasons, such as FIPS mode being enabled.
示例2: past_timestamp
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def past_timestamp(weeks=0, days=0, hours=0, minutes=0, seconds=0):
"""
Produces a timestamp from the past compatible with the API.
Used to provide time ranges by templates.
Expects a dictionary of arguments to timedelta, for example:
datetime.timedelta(hours=24)
datetime.timedelta(days=7)
See: https://docs.python.org/3/library/datetime.html#datetime.timedelta
"""
delta = dict()
if weeks:
delta["weeks"] = weeks
if days:
delta["days"] = days
if hours:
delta["hours"] = hours
if minutes:
delta["minutes"] = minutes
if seconds:
delta["seconds"] = seconds
return (datetime.datetime.now() - datetime.timedelta(**delta)).isoformat()
示例3: validate
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def validate(self, value):
validation_errors = super(DateTimeField, self).validate(value)
if value is None:
pass
elif not isinstance(value, datetime.datetime):
validation_errors.append('The value is not a datetime')
elif value.utcoffset() is None:
validation_errors.append('The value is a naive datetime.')
elif value.utcoffset().total_seconds() != 0:
validation_errors.append('The value must use UTC timezone.')
elif value.year < 1900:
# https://docs.python.org/2/library/datetime.html?highlight=strftime#strftime-strptime-behavior
# "The exact range of years for which strftime() works also varies across platforms. Regardless of platform, years before 1900 cannot be used."
validation_errors.append('The value must be a date after 1900.')
return validation_errors
示例4: from_grib_date_time
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def from_grib_date_time(message, date_key='dataDate', time_key='dataTime', epoch=DEFAULT_EPOCH):
# type: (T.Mapping, str, str, datetime.datetime) -> int
"""
Return the number of seconds since the ``epoch`` from the values of the ``message`` keys,
using datetime.total_seconds().
:param message: the target GRIB message
:param date_key: the date key, defaults to "dataDate"
:param time_key: the time key, defaults to "dataTime"
:param epoch: the reference datetime
"""
date = message[date_key]
time = message[time_key]
hour = time // 100
minute = time % 100
year = date // 10000
month = date // 100 % 100
day = date % 100
data_datetime = datetime.datetime(year, month, day, hour, minute)
# Python 2 compatible timestamp implementation without timezone hurdle
# see: https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp
return int((data_datetime - epoch).total_seconds())
示例5: tzname
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def tzname(self, dt):
"""
http://docs.python.org/library/datetime.html#datetime.tzinfo.tzname
"""
# total_seconds was introduced in Python 2.7
if hasattr(self.__offset, "total_seconds"):
total_seconds = self.__offset.total_seconds()
else:
total_seconds = (self.__offset.days * 24 * 60 * 60) + \
(self.__offset.seconds)
hours = total_seconds // (60 * 60)
total_seconds -= hours * 60 * 60
minutes = total_seconds // 60
total_seconds -= minutes * 60
seconds = total_seconds // 1
total_seconds -= seconds
if seconds:
return "%+03d:%02d:%02d" % (hours, minutes, seconds)
return "%+03d:%02d" % (hours, minutes)
示例6: _format_list
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def _format_list(v):
return '[{0}]'.format(', '.join(_format_value(obj) for obj in v))
# Formula from:
# https://docs.python.org/2/library/datetime.html#datetime.timedelta.total_seconds
# Once support for py26 is dropped, this can be replaced by td.total_seconds()
示例7: __init__
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def __init__(self, pattern, options={}, **kwargs):
"""
:param kwargs: Arguments to pass to Series.str.contains
(http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.contains.html)
pat is the only required argument
"""
self.pattern = pattern
self.options = options
super().__init__(**kwargs)
示例8: is_date_class
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def is_date_class(val):
return isinstance(val, (datetime.date, datetime.datetime, arrow.Arrow, ))
# Calculate seconds since 1970-01-01 (timestamp) in a way that works in
# Python 2 and Python3
# https://docs.python.org/3/library/datetime.html#datetime.datetime.timestamp
示例9: parse_bool
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def parse_bool(s, default=False):
"""
Return the boolean value of an English string or default if it can't be
determined.
"""
if s is None:
return default
return TRUTH.get(s.lower(), default)
# python2 doesn't have a utc tzinfo by default
# see https://docs.python.org/2/library/datetime.html#tzinfo-objects
示例10: utcoffset
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def utcoffset(self, dt):
"""
http://docs.python.org/library/datetime.html#datetime.tzinfo.utcoffset
"""
return self.__offset
示例11: tzname
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def tzname(self, dt):
"""
http://docs.python.org/library/datetime.html#datetime.tzinfo.tzname
"""
sign = '+'
if self.__offset < datetime.timedelta():
sign = '-'
# total_seconds was introduced in Python 2.7
if hasattr(self.__offset, 'total_seconds'):
total_seconds = self.__offset.total_seconds()
else:
total_seconds = (self.__offset.days * 24 * 60 * 60) + \
(self.__offset.seconds) + \
(self.__offset.microseconds / 1000000.0)
hours = total_seconds // (60 * 60)
total_seconds -= hours * 60 * 60
minutes = total_seconds // 60
total_seconds -= minutes * 60
seconds = total_seconds // 1
total_seconds -= seconds
if seconds:
return '%s%02d:%02d:%02d' % (sign, hours, minutes, seconds)
else:
return '%s%02d:%02d' % (sign, hours, minutes)
示例12: dst
# 需要导入模块: import datetime [as 别名]
# 或者: from datetime import html [as 别名]
def dst(self, dt):
"""
http://docs.python.org/library/datetime.html#datetime.tzinfo.dst
"""
return datetime.timedelta(0)