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


Python dates.format_time方法代码示例

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


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

示例1: generate_date

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_time [as 别名]
def generate_date():
    dt = fake.future_datetime(end_date='+30d')

    machine_readable = dt.strftime('%H:%M:%S')
    human_readable = format_time(dt, format=random.choice(ABS_FORMATS), locale='zh_CN')

    r = random.random()
    if r < 0.3:
        machine_readable = 'ABS>' + machine_readable
    elif 0.3 <= r <= 0.7:
        prefix = random.choice([k for k in REL_PREFIXS.keys() if '?' not in k])
        machine_readable = REL_PREFIXS[prefix] + '>' + machine_readable
        human_readable = prefix + human_readable
    else:
        prefix = random.choice([k for k in REL_PREFIXS.keys() if '?' in k])
        machine_readable = REL_PREFIXS[prefix]
        human_readable = prefix

    return human_readable, machine_readable, dt 
开发者ID:Sorosliu1029,项目名称:Jike-Metro,代码行数:21,代码来源:generate_dataset.py

示例2: time_filter

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

示例3: prepare_activity_conversation_message_notification

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_time [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

示例4: format_time

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

        :param time:
            A ``time`` or ``datetime`` object. If None, the current
            time 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:  4:36 PM
            - medium: 4:36:05 PM
            - long:   4:36:05 PM +0000
            - full:   4:36:05 PM World (GMT) Time

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

        kwargs = {}
        if rebase:
            kwargs['tzinfo'] = self.tzinfo

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

示例5: format_history_message

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_time [as 别名]
def format_history_message(self, recipient, buffer_entry):
		return format_time(buffer_entry['time'], format='short', locale=recipient.get_locale())+" - "+buffer_entry['sender']+": "+buffer_entry['message'].format(buffer_entry['params'])
	
	# prints the history to a player
	# perform recipient check (player not a recipient, error message) 
开发者ID:tspivey,项目名称:yugioh-game,代码行数:7,代码来源:channel.py

示例6: format_history_message

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_time [as 别名]
def format_history_message(self, recipient, buffer_entry):
		return format_time(buffer_entry['time'], format='short', locale=recipient.get_locale())+' - '+recipient._(buffer_entry['message']).format(**self.resolve_closures(recipient, buffer_entry['params'])) 
开发者ID:tspivey,项目名称:yugioh-game,代码行数:4,代码来源:challenge.py

示例7: format_history_message

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_time [as 别名]
def format_history_message(self, recipient, buffer_entry):
		return format_time(buffer_entry['time'], format='short', locale=recipient.get_locale())+' - '+buffer_entry['sender']+': '+buffer_entry['message'] 
开发者ID:tspivey,项目名称:yugioh-game,代码行数:4,代码来源:tag.py

示例8: format_history_message

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_time [as 别名]
def format_history_message(self, recipient, buffer_entry):
		if buffer_entry['sender'] is None:
			msg = recipient._("You tell %s: %s")%(buffer_entry['params']['receiving_player'], buffer_entry['message'])
		else:
			msg = recipient._("%s tells you: %s")%(buffer_entry['sender'], buffer_entry['message'])
		return format_time(buffer_entry['time'], format='short', locale=recipient.get_locale())+" - "+msg 
开发者ID:tspivey,项目名称:yugioh-game,代码行数:8,代码来源:tell.py

示例9: format_history_message

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_time [as 别名]
def format_history_message(self, recipient, buffer_entry):
		return format_time(buffer_entry['time'], format='short', locale=recipient.get_locale())+" - "+recipient._(buffer_entry['message']).format(buffer_entry['sender']) 
开发者ID:tspivey,项目名称:yugioh-game,代码行数:4,代码来源:watchers.py

示例10: format_time_localized

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

示例11: format_time

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

示例12: format_cell

# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_time [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_time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。