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


Python date.year方法代码示例

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


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

示例1: apply

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:offsets.py

示例2: daterange_with_details

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [as 别名]
def daterange_with_details(value):
    '''Display a date range in the shorter possible maner.'''
    delta = value.end - value.start
    start, end = None, None
    if is_first_year_day(value.start) and is_last_year_day(value.end):
        start = value.start.year
        if delta.days > 365:
            end = value.end.year
    elif is_first_month_day(value.start) and is_last_month_day(value.end):
        start = short_month(value.start)
        if delta.days > 31:
            end = short_month(value.end)
    else:
        start = short_day(value.start)
        if value.start != value.end:
            end = short_day(value.end)
    return _('%(start)s to %(end)s', start=start, end=end) if end else start 
开发者ID:opendatateam,项目名称:udata,代码行数:19,代码来源:helpers.py

示例3: dga

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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 
开发者ID:pchaigno,项目名称:dga-collection,代码行数:24,代码来源:ranbyus.py

示例4: from_date_time_string

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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) 
开发者ID:ladybug-tools,项目名称:ladybug,代码行数:25,代码来源:dt.py

示例5: dateToString

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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 
开发者ID:Jooyeshgar,项目名称:amir,代码行数:19,代码来源:dateentry.py

示例6: stringToDate

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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
## @{ 
开发者ID:Jooyeshgar,项目名称:amir,代码行数:22,代码来源:dateentry.py

示例7: showDate

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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. 
开发者ID:Jooyeshgar,项目名称:amir,代码行数:18,代码来源:dateentry.py

示例8: _next_opening_time

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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) 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:19,代码来源:offsets.py

示例9: apply

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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 = other + timedelta(days=first - other.day)
            n -= 1

        other = other + relativedelta(months=n)
        wkday, _ = tslib.monthrange(other.year, other.month)
        first = _get_firstbday(wkday)
        result = datetime(other.year, other.month, first,
                          other.hour, other.minute,
                          other.second, other.microsecond)
        return result 
开发者ID:nccgroup,项目名称:Splunking-Crime,代码行数:21,代码来源:offsets.py

示例10: rollback

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:offsets.py

示例11: rollforward

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:10,代码来源:offsets.py

示例12: onOffset

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [as 别名]
def onOffset(cls, dt):
        days_in_month = tslib.monthrange(dt.year, dt.month)[1]
        return dt.day == days_in_month 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:5,代码来源:offsets.py

示例13: getOffsetOfMonth

# 需要导入模块: from datetime import date [as 别名]
# 或者: from datetime.date import year [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 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:12,代码来源:offsets.py


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