class Format(object):
Wrapper class providing the various date and number formatting functions bound to a specific locale and time-zone.
>>> from babel.util import UTC >>> from datetime import date >>> fmt = Format('en_US', UTC) >>> fmt.date(date(2007, 4, 1)) u'Apr 1, 2007' >>> fmt.decimal(1.2345) u'1.234'
Method | currency |
Return a number in the given currency formatted for the locale. |
Method | date |
Return a date formatted according to the given pattern. |
Method | datetime |
Return a date and time formatted according to the given pattern. |
Method | decimal |
Return a decimal number formatted for the locale. |
Method | number |
Return an integer number formatted for the locale. |
Method | percent |
Return a number formatted as percentage for the locale. |
Method | scientific |
Return a number formatted using scientific notation for the locale. |
Method | time |
Return a time formatted according to the given pattern. |
Method | timedelta |
Return a time delta according to the rules of the given locale. |
Method | __init__ |
Initialize the formatter. |
Instance Variable | locale |
Undocumented |
Instance Variable | tzinfo |
Undocumented |
Return a date formatted according to the given pattern.
>>> from datetime import date >>> fmt = Format('en_US') >>> fmt.date(date(2007, 4, 1)) u'Apr 1, 2007'
Return a date and time formatted according to the given pattern.
>>> from datetime import datetime >>> from pytz import timezone >>> fmt = Format('en_US', tzinfo=timezone('US/Eastern')) >>> fmt.datetime(datetime(2007, 4, 1, 15, 30)) u'Apr 1, 2007, 11:30:00 AM'
Return a decimal number formatted for the locale.
>>> fmt = Format('en_US') >>> fmt.decimal(1.2345) u'1.234'
Return an integer number formatted for the locale.
>>> fmt = Format('en_US') >>> fmt.number(1099) u'1,099'
Return a number formatted as percentage for the locale.
>>> fmt = Format('en_US') >>> fmt.percent(0.34) u'34%'
Return a time formatted according to the given pattern.
>>> from datetime import datetime >>> from pytz import timezone >>> fmt = Format('en_US', tzinfo=timezone('US/Eastern')) >>> fmt.time(datetime(2007, 4, 1, 15, 30)) u'11:30:00 AM'
Return a time delta according to the rules of the given locale.
>>> from datetime import timedelta >>> fmt = Format('en_US') >>> fmt.timedelta(timedelta(weeks=11)) u'3 months'