当前位置: 首页>>代码示例>>Python>>正文


Python time.hour方法代码示例

本文整理汇总了Python中datetime.time.hour方法的典型用法代码示例。如果您正苦于以下问题:Python time.hour方法的具体用法?Python time.hour怎么用?Python time.hour使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在datetime.time的用法示例。


在下文中一共展示了time.hour方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: extract

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def extract(self, char):
        char = str(char)[0]
        if char == 'y':
            return self.value.year
        elif char == 'M':
            return self.value.month
        elif char == 'd':
            return self.value.day
        elif char == 'H':
            return self.value.hour
        elif char == 'h':
            return self.value.hour % 12 or 12
        elif char == 'm':
            return self.value.minute
        elif char == 'a':
            return int(self.value.hour >= 12)  # 0 for am, 1 for pm
        else:
            raise NotImplementedError("Not implemented: extracting %r from %r" % (char, self.value)) 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:20,代码来源:dates.py

示例2: from_dict

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def from_dict(cls, data):
        """Create datetime from a dictionary.

        Args:
            data: A python dictionary in the following format

        .. code-block:: python

                {
                'month': 1  #A value for month between 1-12. (Default: 1)
                'day': 1  # A value for day between 1-31. (Default: 1)
                'hour': 0  # A value for hour between 0-23. (Default: 0)
                'minute': 0  # A value for month between 0-59. (Default: 0)
                }
        """
        month = data['month'] if 'month' in data else 1
        day = data['day'] if 'day' in data else 1
        hour = data['hour'] if 'hour' in data else 0
        minute = data['minute'] if 'minute' in data else 0
        leap_year = data['leap_year'] if 'leap_year' in data else False
        return cls(month, day, hour, minute, leap_year) 
开发者ID:ladybug-tools,项目名称:ladybug,代码行数:23,代码来源:dt.py

示例3: _partial_date_slice

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def _partial_date_slice(self, reso, parsed, use_lhs=True, use_rhs=True):
        is_monotonic = self.is_monotonic
        if (is_monotonic and reso in ['day', 'hour', 'minute', 'second'] and
                self._resolution >= Resolution.get_reso(reso)):
            # These resolution/monotonicity validations came from GH3931,
            # GH3452 and GH2369.

            # See also GH14826
            raise KeyError

        if reso == 'microsecond':
            # _partial_date_slice doesn't allow microsecond resolution, but
            # _parsed_string_to_bounds allows it.
            raise KeyError

        t1, t2 = self._parsed_string_to_bounds(reso, parsed)
        stamps = self.asi8

        if is_monotonic:

            # we are out of range
            if (len(stamps) and ((use_lhs and t1.value < stamps[0] and
                                  t2.value < stamps[0]) or
                                 ((use_rhs and t1.value > stamps[-1] and
                                   t2.value > stamps[-1])))):
                raise KeyError

            # a monotonic (sorted) series can be sliced
            left = stamps.searchsorted(
                t1.value, side='left') if use_lhs else None
            right = stamps.searchsorted(
                t2.value, side='right') if use_rhs else None

            return slice(left, right)

        lhs_mask = (stamps >= t1.value) if use_lhs else True
        rhs_mask = (stamps <= t2.value) if use_rhs else True

        # try to find a the dates
        return (lhs_mask & rhs_mask).nonzero()[0] 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:42,代码来源:datetimes.py

示例4: _time_to_micros

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def _time_to_micros(time):
    seconds = time.hour * 60 * 60 + 60 * time.minute + time.second
    return 1000000 * seconds + time.microsecond 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:5,代码来源:datetimes.py

示例5: to_julian_date

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def to_julian_date(self):
        """
        Convert DatetimeIndex to Float64Index of Julian Dates.
        0 Julian date is noon January 1, 4713 BC.
        http://en.wikipedia.org/wiki/Julian_day
        """

        # http://mysite.verizon.net/aesir_research/date/jdalg2.htm
        year = np.asarray(self.year)
        month = np.asarray(self.month)
        day = np.asarray(self.day)
        testarr = month < 3
        year[testarr] -= 1
        month[testarr] += 12
        return Float64Index(day +
                            np.fix((153 * month - 457) / 5) +
                            365 * year +
                            np.floor(year / 4) -
                            np.floor(year / 100) +
                            np.floor(year / 400) +
                            1721118.5 +
                            (self.hour +
                             self.minute / 60.0 +
                             self.second / 3600.0 +
                             self.microsecond / 3600.0 / 1e+6 +
                             self.nanosecond / 3600.0 / 1e+9
                             ) / 24.0) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:29,代码来源:datetimes.py

示例6: resolution

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def resolution(self):
        """
        Returns day, hour, minute, second, or microsecond
        """
        reso = self._resolution
        return get_reso_string(reso) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:8,代码来源:index.py

示例7: _ensure_datetime_tzinfo

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def _ensure_datetime_tzinfo(datetime, tzinfo=None):
    """
    Ensure the datetime passed has an attached tzinfo.

    If the datetime is tz-naive to begin with, UTC is attached.

    If a tzinfo is passed in, the datetime is normalized to that timezone.

    >>> _ensure_datetime_tzinfo(datetime(2015, 1, 1)).tzinfo.zone
    'UTC'

    >>> tz = get_timezone("Europe/Stockholm")
    >>> _ensure_datetime_tzinfo(datetime(2015, 1, 1, 13, 15, tzinfo=UTC), tzinfo=tz).hour
    14

    :param datetime: Datetime to augment.
    :param tzinfo: Optional tznfo.
    :return: datetime with tzinfo
    :rtype: datetime
    """
    if datetime.tzinfo is None:
        datetime = datetime.replace(tzinfo=UTC)
    if tzinfo is not None:
        datetime = datetime.astimezone(get_timezone(tzinfo))
        if hasattr(tzinfo, 'normalize'):  # pytz
            datetime = tzinfo.normalize(datetime)
    return datetime 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:29,代码来源:dates.py

示例8: parse_time

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def parse_time(string, locale=LC_TIME):
    """Parse a time from a string.

    This function uses the time format for the locale as a hint to determine
    the order in which the time fields appear in the string.

    >>> parse_time('15:30:00', locale='en_US')
    datetime.time(15, 30)

    :param string: the string containing the time
    :param locale: a `Locale` object or a locale identifier
    :return: the parsed time
    :rtype: `time`
    """
    # TODO: try ISO format first?
    format = get_time_format(locale=locale).pattern.lower()
    hour_idx = format.index('h')
    if hour_idx < 0:
        hour_idx = format.index('k')
    min_idx = format.index('m')
    sec_idx = format.index('s')

    indexes = [(hour_idx, 'H'), (min_idx, 'M'), (sec_idx, 'S')]
    indexes.sort()
    indexes = dict([(item[1], idx) for idx, item in enumerate(indexes)])

    # FIXME: support 12 hour clock, and 0-based hour specification
    #        and seconds should be optional, maybe minutes too
    #        oh, and time-zones, of course

    numbers = re.findall(r'(\d+)', string)
    hour = int(numbers[indexes['H']])
    minute = int(numbers[indexes['M']])
    second = int(numbers[indexes['S']])
    return time(hour, minute, second) 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:37,代码来源:dates.py

示例9: format_milliseconds_in_day

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def format_milliseconds_in_day(self, num):
        msecs = self.value.microsecond // 1000 + self.value.second * 1000 + \
            self.value.minute * 60000 + self.value.hour * 3600000
        return self.format(msecs, num) 
开发者ID:luckystarufo,项目名称:pySINDy,代码行数:6,代码来源:dates.py

示例10: __new__

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def __new__(cls, month=1, day=1, hour=0, minute=0, leap_year=False):
        """Create Ladybug datetime.
        """
        year = 2016 if leap_year else 2017
        hour, minute = Time._calculate_hour_and_minute(hour + minute / 60.0)
        try:
            return datetime.__new__(cls, year, month, day, hour, minute)
        except ValueError as e:
            raise ValueError("{}:\n\t({}/{}@{}:{})(m/d@h:m)".format(
                e, month, day, hour, minute
            )) 
开发者ID:ladybug-tools,项目名称:ladybug,代码行数:13,代码来源:dt.py

示例11: __reduce_ex__

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def __reduce_ex__(self, protocol):
        """Call the __new__() constructor when the class instance is unpickled.

        This method is necessary for the pickle.loads() call to work.
        """
        return (type(self), (self.month, self.day, self.hour, self.minute)) 
开发者ID:ladybug-tools,项目名称:ladybug,代码行数:8,代码来源:dt.py

示例12: from_hoy

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def from_hoy(cls, hoy, leap_year=False):
        """Create Ladybug Datetime from an hour of the year.

        Args:
            hoy: A float value 0 <= and < 8760
            leap_year: Boolean to note whether the Date Time is a part of a
                leap year. Default: False.
        """
        return cls.from_moy(round(hoy * 60), leap_year) 
开发者ID:ladybug-tools,项目名称:ladybug,代码行数:11,代码来源:dt.py

示例13: from_moy

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def from_moy(cls, moy, leap_year=False):
        """Create Ladybug Datetime from a minute of the year.

        Args:
            moy: An integer value 0 <= and < 525600
            leap_year: Boolean to note whether the Date Time is a part of a
                leap year. Default: False.
        """
        if not leap_year:
            num_of_minutes_until_month = (0, 44640, 84960, 129600, 172800, 217440,
                                          260640, 305280, 349920, 393120, 437760,
                                          480960, 525600)
        else:
            num_of_minutes_until_month = (0, 44640, 84960 + 1440, 129600 + 1440,
                                          172800 + 1440, 217440 + 1440, 260640 + 1440,
                                          305280 + 1440, 349920 + 1440, 393120 + 1440,
                                          437760 + 1440, 480960 + 1440, 525600 + 1440)
        # find month
        moy = int(moy)
        for month_count in range(12):
            if moy < num_of_minutes_until_month[month_count + 1]:
                month = month_count + 1
                break
        try:
            day = int((moy - num_of_minutes_until_month[month - 1]) / (60 * 24)) + 1
        except UnboundLocalError:
            raise ValueError(
                "moy must be positive and smaller than 525600. Invalid input %d" % (moy)
            )
        else:
            hour = int((moy / 60) % 24)
            minute = int(moy % 60)

            return cls(month, day, hour, minute, leap_year) 
开发者ID:ladybug-tools,项目名称:ladybug,代码行数:36,代码来源:dt.py

示例14: from_array

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def from_array(cls, datetime_array):
        """Create Ladybug DateTime from am array of integers.

        Args:
            datetime_array: An array of 4 integers (and optional leap_year boolean)
                ordered as follows: (month, day, hour, minute, leap_year)
        """
        return cls(*datetime_array) 
开发者ID:ladybug-tools,项目名称:ladybug,代码行数:10,代码来源:dt.py

示例15: from_date_and_time

# 需要导入模块: from datetime import time [as 别名]
# 或者: from datetime.time import hour [as 别名]
def from_date_and_time(cls, date, time):
        """Create Ladybug DateTime from a Date and a Time object.

        Args:
            date: A ladybug Date object.
            time: A ladybug Time object.
        """
        leap_year = True if date.year % 4 == 0 else False
        return cls(date.month, date.day, time.hour, time.minute, leap_year) 
开发者ID:ladybug-tools,项目名称:ladybug,代码行数:11,代码来源:dt.py


注:本文中的datetime.time.hour方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。