本文整理汇总了Python中babel.dates.format_datetime方法的典型用法代码示例。如果您正苦于以下问题:Python dates.format_datetime方法的具体用法?Python dates.format_datetime怎么用?Python dates.format_datetime使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类babel.dates
的用法示例。
在下文中一共展示了dates.format_datetime方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: admin
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def admin():
version = updater_thread.get_current_version_info()
if version is False:
commit = _(u'Unknown')
else:
if 'datetime' in version:
commit = version['datetime']
tz = timedelta(seconds=time.timezone if (time.localtime().tm_isdst == 0) else time.altzone)
form_date = datetime.strptime(commit[:19], "%Y-%m-%dT%H:%M:%S")
if len(commit) > 19: # check if string has timezone
if commit[19] == '+':
form_date -= timedelta(hours=int(commit[20:22]), minutes=int(commit[23:]))
elif commit[19] == '-':
form_date += timedelta(hours=int(commit[20:22]), minutes=int(commit[23:]))
commit = format_datetime(form_date - tz, format='short', locale=get_locale())
else:
commit = version['version']
allUser = ub.session.query(ub.User).all()
email_settings = config.get_mail_settings()
return render_title_template("admin.html", allUser=allUser, email=email_settings, config=config, commit=commit,
title=_(u"Admin page"), page="admin")
示例2: draw_date
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def draw_date(config, geo_data):
"""
"""
tzinfo = pytz.timezone(geo_data["timezone"])
locale = config.get("locale", "en_US")
datetime_day_start = datetime.datetime.utcnow()
answer = ""
for day in range(3):
datetime_ = datetime_day_start + datetime.timedelta(hours=24*day)
date = format_datetime(datetime_, "EEE dd MMM", locale=locale, tzinfo=tzinfo)
spaces = ((24-len(date))//2)*" "
date = spaces + date + spaces
date = " "*(24-len(date)) + date
answer += date
answer += "\n"
for _ in range(3):
answer += " "*23 + u"╷"
return answer[:-1] + " "
# }}}
# draw_time {{{
示例3: _date_filter
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def _date_filter(value, format='medium'):
if format == 'full':
format = 'EEEE, d. MMMM y \'at\' HH:mm zzzz'
elif format == 'medium':
format = 'EE dd.MM.y HH:mm zzzz'
return format_datetime(value, format, locale='en_US')
示例4: format_datetime
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def format_datetime(self, datetime=None, format=None, rebase=True):
"""Returns a date and time formatted according to the given pattern
and following the current locale and timezone.
:param datetime:
A ``datetime`` object. If None, the current date and 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: 11/10/09 4:36 PM
- medium: Nov 10, 2009 4:36:05 PM
- long: November 10, 2009 4:36:05 PM +0000
- full: Tuesday, November 10, 2009 4:36:05 PM World (GMT) Time
:param rebase:
If True, converts the datetime to the current :attr:`timezone`.
:returns:
A formatted date and time in unicode.
"""
format = self._get_format('datetime', format)
kwargs = {}
if rebase:
kwargs['tzinfo'] = self.tzinfo
return dates.format_datetime(datetime, format, locale=self.locale,
**kwargs)
示例5: td_format
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def td_format(self, content):
if content:
return format_datetime(content, self.datetime_format)
else:
return ''
示例6: get_formatted_value
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def get_formatted_value(self, value, parameter, object_id, pattern=None, is_array_item=False):
rv = ''
if is_array_item and parameter.type == ParameterType.simple_array:
value_type = parameter.array_item_type
else:
value_type = parameter.type
if value_type == ParameterType.string:
rv = value
elif value_type in (ParameterType.number, ParameterType.average, ParameterType.sum):
if pattern:
used_pattern = pattern
pattern_has_currency = (pattern.find('$') != -1)
else:
used_pattern = parameter.pattern
pattern_has_currency = parameter.pattern_has_currency
if used_pattern:
try:
value = format_decimal(value, used_pattern, locale=self.pattern_locale)
if pattern_has_currency:
value = value.replace('$', self.pattern_currency_symbol)
rv = value
except ValueError:
error_object_id = object_id if pattern else parameter.id
raise ReportBroError(
Error('errorMsgInvalidPattern', object_id=error_object_id, field='pattern', context=value))
else:
rv = str(value)
elif value_type == ParameterType.date:
used_pattern = pattern if pattern else parameter.pattern
if used_pattern:
try:
rv = format_datetime(value, used_pattern, locale=self.pattern_locale)
except ValueError:
error_object_id = object_id if pattern else parameter.id
raise ReportBroError(
Error('errorMsgInvalidPattern',
object_id=error_object_id, field='pattern', context=value))
else:
rv = str(value)
return rv
示例7: datetime_filter
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def datetime_filter(s):
if s is None or s == 0 or not len(str(s)):
return ''
return format_datetime(s, locale='en_GB', format='short')
示例8: format_datetime_localized
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def format_datetime_localized(self, dt):
"""Formats a datetime object to a localized human-readable string based
on the current locale."""
return format_datetime(dt, locale=self.__get_env_language_for_babel());
示例9: format_datetime
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def format_datetime(date, fmt, locale=LC_TIME, tzinfo=None):
fmt = normalize_datetime_format(fmt)
return babel_dates.format_datetime(date, fmt, locale=locale, tzinfo=tzinfo)
示例10: format_cell
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [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
示例11: render_task_status
# 需要导入模块: from babel import dates [as 别名]
# 或者: from babel.dates import format_datetime [as 别名]
def render_task_status(tasklist):
renderedtasklist = list()
for task in tasklist:
if task['user'] == current_user.nickname or current_user.role_admin():
if task['formStarttime']:
task['starttime'] = format_datetime(task['formStarttime'], format='short', locale=get_locale())
# task2['formStarttime'] = ""
else:
if 'starttime' not in task:
task['starttime'] = ""
if 'formRuntime' not in task:
task['runtime'] = ""
else:
task['runtime'] = format_runtime(task['formRuntime'])
# localize the task status
if isinstance( task['stat'], int):
if task['stat'] == STAT_WAITING:
task['status'] = _(u'Waiting')
elif task['stat'] == STAT_FAIL:
task['status'] = _(u'Failed')
elif task['stat'] == STAT_STARTED:
task['status'] = _(u'Started')
elif task['stat'] == STAT_FINISH_SUCCESS:
task['status'] = _(u'Finished')
else:
task['status'] = _(u'Unknown Status')
# localize the task type
if isinstance( task['taskType'], int):
if task['taskType'] == TASK_EMAIL:
task['taskMessage'] = _(u'E-mail: ') + task['taskMess']
elif task['taskType'] == TASK_CONVERT:
task['taskMessage'] = _(u'Convert: ') + task['taskMess']
elif task['taskType'] == TASK_UPLOAD:
task['taskMessage'] = _(u'Upload: ') + task['taskMess']
elif task['taskType'] == TASK_CONVERT_ANY:
task['taskMessage'] = _(u'Convert: ') + task['taskMess']
else:
task['taskMessage'] = _(u'Unknown Task: ') + task['taskMess']
renderedtasklist.append(task)
return renderedtasklist