Home | Trees | Indices | Help |
|
---|
|
Locale dependent formatting and parsing of dates and times.
The default locale for the functions in this module is determined by the following environment variables, in that order:
- LC_TIME,
- LC_ALL, and
- LANG
Functions | |||
unicode
|
|
||
unicode
|
|
||
unicode
|
|
||
date |
|
||
datetime |
|
||
time |
|
Function Details |
Return a date formatted according to the given pattern. >>> d = date(2007, 04, 01) >>> format_date(d, locale='en_US') u'Apr 1, 2007' >>> format_date(d, format='full', locale='de_DE') u'Sonntag, 1. April 2007' If you don't want to use the locale default formats, you can specify a custom date pattern: >>> format_date(d, "EEE, MMM d, ''yy", locale='en') u"Sun, Apr 1, '07"
Note:
If the pattern contains time fields, an |
Return a date formatted according to the given pattern. >>> dt = datetime(2007, 04, 01, 15, 30) >>> format_datetime(dt, locale='en_US') u'Apr 1, 2007 3:30:00 PM' For any pattern requiring the display of the time-zone, the third-party pytz package is needed to explicitly specify the time-zone: >>> from pytz import timezone >>> format_datetime(dt, 'full', tzinfo=timezone('Europe/Berlin'), ... locale='de_DE') u'Sonntag, 1. April 2007 17:30 Uhr MESZ' >>> format_datetime(dt, "yyyy.MM.dd G 'at' HH:mm:ss zzz", ... tzinfo=timezone('US/Eastern'), locale='en') u'2007.04.01 AD at 11:30:00 EDT'
|
Return a time formatted according to the given pattern. >>> t = time(15, 30) >>> format_time(t, locale='en_US') u'3:30:00 PM' >>> format_time(t, format='short', locale='de_DE') u'15:30' If you don't want to use the locale default formats, you can specify a custom time pattern: >>> format_time(t, "hh 'o''clock' a", locale='en') u"03 o'clock PM" For any pattern requiring the display of the time-zone, the third-party pytz package is needed to explicitly specify the time-zone: >>> from pytz import timezone >>> t = time(15, 30) >>> format_time(t, format='full', tzinfo=timezone('Europe/Berlin'), ... locale='de_DE') u'17:30 Uhr MESZ' >>> format_time(t, "hh 'o''clock' a, zzzz", tzinfo=timezone('US/Eastern'), ... locale='en') u"11 o'clock AM, Eastern Daylight Time"
Note:
If the pattern contains date fields, an |
Parse a date from a string. This function uses the date format for the locale as a hint to determine the order in which the date fields appear in the string. >>> parse_date('4/1/04', locale='en_US') datetime.date(2004, 4, 1) >>> parse_date('01.04.2004', locale='de_DE') datetime.date(2004, 4, 1)
|
Parse a date and time from a string. This function uses the date and time formats for the locale as a hint to determine the order in which the time fields appear in the string.
|
Parse a time from a string. This function uses the time format for the locale as a hint to determine the order in which the time fields appear in the string. >>> parse_time('15:30:00', locale='en_US') datetime.time(15, 30)
|
Home | Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0beta1 on Mon Jul 2 11:34:40 2007 | http://epydoc.sourceforge.net |