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


Python datetime.html方法代碼示例

本文整理匯總了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. 
開發者ID:skarlekar,項目名稱:faces,代碼行數:26,代碼來源:compat.py

示例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() 
開發者ID:ansible-community,項目名稱:ara,代碼行數:24,代碼來源:datetime_formatting.py

示例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 
開發者ID:edx,項目名稱:edx-analytics-pipeline,代碼行數:18,代碼來源:record.py

示例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()) 
開發者ID:ecmwf,項目名稱:cfgrib,代碼行數:24,代碼來源:cfmessage.py

示例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) 
開發者ID:suds-community,項目名稱:suds,代碼行數:26,代碼來源:date.py

示例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() 
開發者ID:HaoZhang95,項目名稱:Python24,代碼行數:8,代碼來源:writer.py

示例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) 
開發者ID:TMiguelT,項目名稱:PandasSchema,代碼行數:11,代碼來源:validation.py

示例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 
開發者ID:magnific0,項目名稱:nokia-weight-sync,代碼行數:9,代碼來源:nokia.py

示例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 
開發者ID:RedHatInsights,項目名稱:insights-core,代碼行數:14,代碼來源:__init__.py

示例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 
開發者ID:cackharot,項目名稱:suds-py3,代碼行數:8,代碼來源:date.py

示例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) 
開發者ID:cackharot,項目名稱:suds-py3,代碼行數:32,代碼來源:date.py

示例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) 
開發者ID:cackharot,項目名稱:suds-py3,代碼行數:8,代碼來源:date.py


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