Mercurial > babel > old > babel-test
comparison doc/formatting.txt @ 34:3666f3d3df15
Extended time-zone support.
author | cmlenz |
---|---|
date | Mon, 04 Jun 2007 16:03:12 +0000 |
parents | 48cf004aa357 |
children | b6c51490cc95 |
comparison
equal
deleted
inserted
replaced
33:0740b6d31799 | 34:3666f3d3df15 |
---|---|
206 third-party package `pytz`_, which includes the definitions of practically all | 206 third-party package `pytz`_, which includes the definitions of practically all |
207 of the time-zones used on the world, as well as important functions for | 207 of the time-zones used on the world, as well as important functions for |
208 reliably converting from UTC to local time, and vice versa:: | 208 reliably converting from UTC to local time, and vice versa:: |
209 | 209 |
210 >>> from datetime import time | 210 >>> from datetime import time |
211 >>> t = time(15, 30) | 211 >>> from pytz import timezone, utc |
212 | 212 >>> dt = datetime(2007, 04, 01, 15, 30, tzinfo=utc) |
213 >>> from pytz import timezone | 213 >>> eastern = timezone('US/Eastern') |
214 >>> cet = timezone('Europe/Berlin') | 214 >>> format_datetime(dt, 'H:mm Z', tzinfo=eastern, locale='en_US') |
215 >>> format_time(t, 'H:mm Z', tzinfo=cet, locale='de_DE') | 215 u'11:30 -0400' |
216 u'15:30 +0100' | |
217 | 216 |
218 The recommended approach to deal with different time-zones in a Python | 217 The recommended approach to deal with different time-zones in a Python |
219 application is to always use UTC internally, and only convert from/to the users | 218 application is to always use UTC internally, and only convert from/to the users |
220 time-zone when accepting user input and displaying date/time data, respectively. | 219 time-zone when accepting user input and displaying date/time data, respectively. |
220 You can use Babel together with ``pytz`` to apply a time-zone to any | |
221 ``datetime`` or ``time`` object for display, leaving the original information | |
222 unchanged:: | |
223 | |
224 >>> british = timezone('Europe/London') | |
225 >>> format_datetime(dt, 'H:mm zzzz', tzinfo=british, locale='en_US') | |
226 u'16:30 British Summer Time' | |
221 | 227 |
222 .. _`pytz`: http://pytz.sourceforge.net/ | 228 .. _`pytz`: http://pytz.sourceforge.net/ |
223 | |
224 | 229 |
225 | 230 |
226 Parsing Dates | 231 Parsing Dates |
227 ------------- | 232 ------------- |
228 | 233 |
307 Parsing Numbers | 312 Parsing Numbers |
308 --------------- | 313 --------------- |
309 | 314 |
310 Babel can also parse numeric data in a locale-sensitive manner:: | 315 Babel can also parse numeric data in a locale-sensitive manner:: |
311 | 316 |
312 >>> from babel.dates import parse_decimal, parse_number | 317 >>> from babel.numbers import parse_decimal, parse_number |
313 | 318 |
314 Examples:: | 319 Examples:: |
315 | 320 |
316 >>> parse_decimal('1,099.98', locale='en_US') | 321 >>> parse_decimal('1,099.98', locale='en_US') |
317 1099.98 | 322 1099.98 |