本文整理匯總了Python中datetime.date.month方法的典型用法代碼示例。如果您正苦於以下問題:Python date.month方法的具體用法?Python date.month怎麽用?Python date.month使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類datetime.date
的用法示例。
在下文中一共展示了date.month方法的14個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: from_dict
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [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)
示例2: apply
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def apply(self, other):
n = self.n
wkday, _ = tslib.monthrange(other.year, other.month)
first = _get_firstbday(wkday)
if other.day > first and n <= 0:
# as if rolled forward already
n += 1
elif other.day < first and n > 0:
other = as_datetime(other) + timedelta(days=first - other.day)
n -= 1
other = as_datetime(other) + relativedelta(months=n)
wkday, _ = tslib.monthrange(other.year, other.month)
first = _get_firstbday(wkday)
result = datetime(other.year, other.month, first)
return as_timestamp(result)
示例3: dga
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def dga(date, seed, nr):
tlds = ['.in', '.me', '.cc', '.su', '.tw', '.net', '.com', '.pw', '.org']
tld_index = date.day
day = date.day
month = date.month
year = date.year
uint_mask = 0xFFFFFFFF
for d in range(nr):
domain = ''
for i in range(14):
day = (day >> 15) ^ 16 * (day & 0x1FFF ^ 4 * (seed ^ day))
day &= uint_mask
year_times7 = 7 * year & uint_mask
year = (((year & 0xFFFFFFF0) << 17) & uint_mask) ^ ((year ^ year_times7) >> 11)
month_times4 = 4 * month & uint_mask
month = (14 * (month & 0xFFFFFFFE) & uint_mask) ^ ((month ^ month_times4) >> 8)
seed_times8 = 8 * seed & uint_mask
seed = (seed >> 6) ^ ((day + seed_times8 << 8) & uint_mask) & 0x3FFFF00
x = ((day ^ month ^ year) % 25) + 97
domain += chr(x)
print(domain + tlds[tld_index % 8])
tld_index += 1
示例4: from_date_time_string
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [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)
示例5: dateToString
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def dateToString(date):
if share.config.datetypes[share.config.datetype] == "jalali":
jd = DateEntry.cal.gregorian_to_jd(date.year, date.month, date.day)
(year, month, day) = DateEntry.cal.jd_to_jalali(jd)
else:
(year, month, day) = (date.year, date.month, date.day)
datelist = ["", "", ""]
datelist[share.config.datefields["year"]] = year
datelist[share.config.datefields["month"]] = month
datelist[share.config.datefields["day"]] = day
delim = share.config.datedelims[share.config.datedelim]
datestring = str(datelist[0]) + delim + \
str(datelist[1]) + delim + str(datelist[2])
datestring = LN(datestring, False)
return datestring
示例6: stringToDate
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def stringToDate(dateString):
dateString = convertToLatin(dateString)
delim = share.config.datedelims[share.config.datedelim]
dateList = dateString.split(delim)
if len(dateList) == 3:
if dateList[0] != '' and dateList[1] != '' and dateList[2] != '':
dy = int(dateList[share.config.datefields["year"]])
dm = int(dateList[share.config.datefields["month"]])
dd = int(dateList[share.config.datefields["day"]])
d = (dy, dm, dd)
de = DateEntry(d)
try:
dateObj = de.getDateObject()
except:
return
return dateObj
## @}
## \defgroup Widgets
## @{
示例7: showDate
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def showDate(self, year, month, day):
datelist = ["", "", ""]
datelist[share.config.datefields["year"]] = year
datelist[share.config.datefields["month"]] = month
datelist[share.config.datefields["day"]] = day
delim = share.config.datedelims[share.config.datedelim]
datestring = str(datelist[0]) + delim + \
str(datelist[1]) + delim + str(datelist[2])
datestring = LN(datestring, False)
self.set_text(datestring)
self.year = year
self.month = month
self.day = day
# Assuming that date objects show gregorian date.
示例8: _next_opening_time
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def _next_opening_time(self, other):
"""
If n is positive, return tomorrow's business day opening time.
Otherwise yesterday's business day's opening time.
Opening time always locates on BusinessDay.
Otherwise, closing time may not if business hour extends over midnight.
"""
if not self.next_bday.onOffset(other):
other = other + self.next_bday
else:
if self.n >= 0 and self.start < other.time():
other = other + self.next_bday
elif self.n < 0 and other.time() < self.start:
other = other + self.next_bday
return datetime(other.year, other.month, other.day,
self.start.hour, self.start.minute)
示例9: apply
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def apply(self, other):
n = self.n
if not self.onOffset(other):
_, days_in_month = tslib.monthrange(other.year, other.month)
if 1 < other.day < self.day_of_month:
other += relativedelta(day=self.day_of_month)
if n > 0:
# rollforward so subtract 1
n -= 1
elif self.day_of_month < other.day < days_in_month:
other += relativedelta(day=self.day_of_month)
if n < 0:
# rollforward in the negative direction so add 1
n += 1
elif n == 0:
n = 1
return self._apply(n, other)
示例10: apply_index
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def apply_index(self, i):
# determine how many days away from the 1st of the month we are
days_from_start = i.to_perioddelta('M').asi8
delta = Timedelta(days=self.day_of_month - 1).value
# get boolean array for each element before the day_of_month
before_day_of_month = days_from_start < delta
# get boolean array for each element after the day_of_month
after_day_of_month = days_from_start > delta
# determine the correct n for each date in i
roll = self._get_roll(i, before_day_of_month, after_day_of_month)
# isolate the time since it will be striped away one the next line
time = i.to_perioddelta('D')
# apply the correct number of months
i = (i.to_period('M') + (roll // 2)).to_timestamp()
# apply the correct day
i = self._apply_index_days(i, roll)
return i + time
示例11: rollback
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def rollback(self, dt):
"""Roll provided date backward to next offset only if not on offset"""
if type(dt) == date:
dt = datetime(dt.year, dt.month, dt.day)
if not self.onOffset(dt):
dt = dt - self.__class__(1, **self.kwds)
return dt
示例12: rollforward
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def rollforward(self, dt):
"""Roll provided date forward to next offset only if not on offset"""
if type(dt) == date:
dt = datetime(dt.year, dt.month, dt.day)
if not self.onOffset(dt):
dt = dt + self.__class__(1, **self.kwds)
return dt
示例13: onOffset
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def onOffset(cls, dt):
days_in_month = tslib.monthrange(dt.year, dt.month)[1]
return dt.day == days_in_month
示例14: getOffsetOfMonth
# 需要導入模塊: from datetime import date [as 別名]
# 或者: from datetime.date import month [as 別名]
def getOffsetOfMonth(self, dt):
w = Week(weekday=self.weekday)
d = datetime(dt.year, dt.month, 1)
d = w.rollforward(d)
for i in range(self.week):
d = w.apply(d)
return d