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


Python dates.format_date方法代码示例

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


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

示例1: _textvariable_trace

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def _textvariable_trace(self, *args):
        """Connect StringVar value with selected date."""
        if self._properties.get("selectmode") == "day":
            date = self._textvariable.get()
            if not date:
                self._remove_selection()
                self._sel_date = None
            else:
                try:
                    self._sel_date = self.parse_date(date)
                except Exception:
                    if self._sel_date is None:
                        self._textvariable.set('')
                    else:
                        self._textvariable.set(self.format_date(self._sel_date))
                    raise ValueError("%r is not a valid date." % date)
                else:
                    self._date = self._sel_date.replace(day=1)
                    self._display_calendar()
                    self._display_selection() 
开发者ID:j4321,项目名称:tkcalendar,代码行数:22,代码来源:calendar_.py

示例2: _on_click

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def _on_click(self, event):
        """Select the day on which the user clicked."""
        if self._properties['state'] == 'normal':
            label = event.widget
            if "disabled" not in label.state():
                day = label.cget("text")
                style = label.cget("style")
                if style in ['normal_om.%s.TLabel' % self._style_prefixe, 'we_om.%s.TLabel' % self._style_prefixe]:
                    if label in self._calendar[0]:
                        self._prev_month()
                    else:
                        self._next_month()
                if day:
                    day = int(day)
                    year, month = self._date.year, self._date.month
                    self._remove_selection()
                    self._sel_date = self.date(year, month, day)
                    self._display_selection()
                    if self._textvariable is not None:
                        self._textvariable.set(self.format_date(self._sel_date))
                    self.event_generate("<<CalendarSelected>>") 
开发者ID:j4321,项目名称:tkcalendar,代码行数:23,代码来源:calendar_.py

示例3: formatdate_filter

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def formatdate_filter(val):
    try:
        conformed_timestamp = re.sub(r"[:]|([-](?!((\d{2}[:]\d{2})|(\d{4}))$))", '', val)
        formatdate = datetime.datetime.strptime(conformed_timestamp[:15], "%Y%m%d %H%M%S")
        return format_date(formatdate, format='medium', locale=get_locale())
    except AttributeError as e:
        log.error('Babel error: %s, Current user locale: %s, Current User: %s', e,
                  current_user.locale,
                  current_user.nickname
                  )
        return formatdate 
开发者ID:janeczku,项目名称:calibre-web,代码行数:13,代码来源:jinjia.py

示例4: date_filter

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def date_filter(value):
    return format_date(
        value.astimezone(get_current_timezone()),
        format='full',
        locale=to_locale(get_language()),
    ) 
开发者ID:yunity,项目名称:karrot-backend,代码行数:8,代码来源:email_utils.py

示例5: prepare_activity_conversation_message_notification

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def prepare_activity_conversation_message_notification(user, messages):
    activity = target_from_messages(messages)
    language = language_for_user(user)
    with translation.override(language):
        with timezone.override(activity.place.group.timezone):
            weekday = format_date(
                activity.date.start.astimezone(timezone.get_current_timezone()),
                'EEEE',
                locale=translation.to_locale(language),
            )
            time = format_time(
                activity.date.start,
                format='short',
                locale=translation.to_locale(language),
                tzinfo=timezone.get_current_timezone(),
            )
            date = format_date(
                activity.date.start.astimezone(timezone.get_current_timezone()),
                format='long',
                locale=translation.to_locale(language),
            )

            long_date = '{} {}, {}'.format(weekday, time, date)
            short_date = '{} {}'.format(weekday, time)

            reply_to_name = _('Pickup %(date)s') % {
                'date': short_date,
            }
            conversation_name = _('Pickup %(date)s') % {
                'date': long_date,
            }

        return prepare_message_notification(
            user,
            messages,
            group=activity.place.group,
            reply_to_name=reply_to_name,
            conversation_name=conversation_name,
            conversation_url=activity_detail_url(activity),
            stats_category='activity_conversation_message'
        ) 
开发者ID:yunity,项目名称:karrot-backend,代码行数:43,代码来源:emails.py

示例6: format_date

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def format_date(self, date=None, format=None, rebase=True):
        """Returns a date formatted according to the given pattern and
        following the current locale.

        :param date:
            A ``date`` or ``datetime`` object. If None, the current date in
            UTC is used.
        :param format:
            The format to be returned. Valid values are "short", "medium",
            "long", "full" or a custom date/time pattern. Example outputs:

            - short:  11/10/09
            - medium: Nov 10, 2009
            - long:   November 10, 2009
            - full:   Tuesday, November 10, 2009

        :param rebase:
            If True, converts the date to the current :attr:`timezone`.
        :returns:
            A formatted date in unicode.
        """
        format = self._get_format('date', format)

        if rebase and isinstance(date, datetime.datetime):
            date = self.to_local_timezone(date)

        return dates.format_date(date, format, locale=self.locale) 
开发者ID:google,项目名称:googleapps-message-recall,代码行数:29,代码来源:i18n.py

示例7: td_format

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def td_format(self, content):
        if content:
            return format_date(content, self.date_format)
        else:
            return '' 
开发者ID:plumdog,项目名称:flask_table,代码行数:7,代码来源:columns.py

示例8: create_date

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def create_date():
    """
        Creates some fake dates 
        :returns: tuple containing 
                  1. human formatted string
                  2. machine formatted string
                  3. date object.
    """
    dt = fake.date_object()

    # wrapping this in a try catch because
    # the locale 'vo' and format 'full' will fail
    try:
        human = format_date(dt,
                            format=random.choice(FORMATS),
                            locale=random.choice(LOCALES))

        case_change = random.randint(0,3) # 1/2 chance of case change
        if case_change == 1:
            human = human.upper()
        elif case_change == 2:
            human = human.lower()

        machine = dt.isoformat()
    except AttributeError as e:
        # print(e)
        return None, None, None

    return human, machine, dt 
开发者ID:datalogue,项目名称:keras-attention,代码行数:31,代码来源:generate.py

示例9: format_date

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def format_date(self, date=None):
        """Convert date (datetime.date) to a string in the locale."""
        return format_date(date, self._properties['date_pattern'], self._properties['locale']) 
开发者ID:j4321,项目名称:tkcalendar,代码行数:5,代码来源:calendar_.py

示例10: selection_set

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def selection_set(self, date):
        """
        Set the selection to date.

            date : datetime.date, datetime.datetime or str
                    date to be made visible. If given as a string, it should be
                    in the format corresponding to the calendar locale.

        Do nothing if selectmode == "none".
        """
        if self._properties.get("selectmode") == "day" and self._properties['state'] == 'normal':
            if date is None:
                self.selection_clear()
            else:
                if isinstance(date, self.datetime):
                    self._sel_date = date.date()
                elif isinstance(date, self.date):
                    self._sel_date = date
                else:
                    try:
                        self._sel_date = self.parse_date(date)
                    except Exception as e:
                        raise ValueError("%r is not a valid date." % date)
                if self['mindate'] is not None and self._sel_date < self['mindate']:
                    self._sel_date = self['mindate']
                elif self['maxdate'] is not None and self._sel_date > self['maxdate']:
                    self._sel_date = self['maxdate']
                if self._textvariable is not None:
                    self._textvariable.set(self.format_date(self._sel_date))

                self._date = self._sel_date.replace(day=1)
                self._display_calendar()
                self._display_selection()
                self._btns_date_range() 
开发者ID:j4321,项目名称:tkcalendar,代码行数:36,代码来源:calendar_.py

示例11: get_date

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def get_date(self):
        """Return selected date as string."""
        if self._sel_date is not None:
            return self.format_date(self._sel_date)
        else:
            return ""

    # --- events 
开发者ID:j4321,项目名称:tkcalendar,代码行数:10,代码来源:calendar_.py

示例12: date_filter

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def date_filter(s):
    if s is None or s == 0 or not len(str(s)):
        return ''
    return format_date(s, locale='en_GB', format='short') 
开发者ID:alephdata,项目名称:memorious,代码行数:6,代码来源:views.py

示例13: format_date_localized

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def format_date_localized(self, dt):
        """Formats a datetime object to a localized human-readable string based
        on the current locale containing only the date."""
        return format_date(dt, locale=self.__get_env_language_for_babel()); 
开发者ID:google,项目名称:personfinder,代码行数:6,代码来源:utils.py

示例14: format_date

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def format_date(date, fmt, locale=LC_TIME):
    fmt = normalize_date_format(fmt)
    return babel_dates.format_date(date, fmt, locale) 
开发者ID:Apkawa,项目名称:xlsx2html,代码行数:5,代码来源:format.py

示例15: format_cell

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_date [as 别名]
def format_cell(cell, locale=None, f_cell=None):
    value = cell.value
    formatted_value = value or '&nbsp;'
    number_format = cell.number_format
    if not number_format:
        return format_hyperlink(formatted_value, cell.hyperlink)

    if isinstance(value, six.integer_types) or isinstance(value, float):
        if number_format.lower() != 'general':
            locale = locale or LC_NUMERIC
            formatted_value = format_decimal(value, number_format, locale=locale)

    locale = locale or LC_TIME

    # Possible problem with dd-mmm and more
    number_format = FIX_BUILTIN_FORMATS.get(cell._style.numFmtId, number_format)
    number_format = number_format.split(';')[0]

    if type(value) == datetime.date:
        formatted_value = format_date(value, number_format, locale=locale)
    elif type(value) == datetime.datetime:
        formatted_value = format_datetime(value, number_format, locale=locale)
    elif type(value) == datetime.time:
        formatted_value = format_time(value, number_format, locale=locale)
    if cell.hyperlink:
        return format_hyperlink(formatted_value, cell)
    return formatted_value 
开发者ID:Apkawa,项目名称:xlsx2html,代码行数:29,代码来源:format.py


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