本文整理匯總了Python中datetime.time.minute方法的典型用法代碼示例。如果您正苦於以下問題:Python time.minute方法的具體用法?Python time.minute怎麽用?Python time.minute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類datetime.time
的用法示例。
在下文中一共展示了time.minute方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: extract
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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))
示例2: from_dict
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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)
示例3: from_date_time_string
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [as 別名]
def from_date_time_string(cls, datetime_string, leap_year=False):
"""Create Ladybug DateTime from a DateTime string.
Args:
datetime_string: A text string representing a DateTime
(ie. "21 Jun 12:00")
leap_year: Boolean to note whether the Date Time is a part of a
leap year. Default: False.
Usage:
.. code-block:: python
dt = DateTime.from_date_time_string("31 Dec 12:00")
"""
try:
dt = datetime.strptime(datetime_string, '%d %b %H:%M')
except AttributeError: # older Python version before strptime
vals = datetime_string.split(' ')
tim = vals[-1].split(':')
dt = datetime(2016, MONTHNAMES.index(vals[1]) + 1, int(vals[0]),
int(tim[0]), int(tim[1]))
return cls(dt.month, dt.day, dt.hour, dt.minute, leap_year)
示例4: _partial_date_slice
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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]
示例5: _time_to_micros
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [as 別名]
def _time_to_micros(time):
seconds = time.hour * 60 * 60 + 60 * time.minute + time.second
return 1000000 * seconds + time.microsecond
示例6: to_julian_date
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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)
示例7: resolution
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [as 別名]
def resolution(self):
"""
Returns day, hour, minute, second, or microsecond
"""
reso = self._resolution
return get_reso_string(reso)
示例8: parse_time
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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)
示例9: format_milliseconds_in_day
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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)
示例10: __new__
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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
))
示例11: __reduce_ex__
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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))
示例12: from_moy
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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)
示例13: from_date_and_time
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [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)
示例14: moy
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [as 別名]
def moy(self):
"""Calculate minute of the year for this date time."""
return self.int_hoy * 60 + self.minute # minute of the year
示例15: float_hour
# 需要導入模塊: from datetime import time [as 別名]
# 或者: from datetime.time import minute [as 別名]
def float_hour(self):
"""Get hour and minute as a float value, e.g. 6.25 for 6:15."""
return self.hour + self.minute / 60.0