本文整理汇总了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
示例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(),
)
示例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'
)
示例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)
示例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)
示例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']))
示例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']
示例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
示例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'])
示例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());
示例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)
示例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 ' '
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