comparison doc/formatting.txt @ 31:3956bb7ff93b

More work on timezones.
author cmlenz
date Mon, 04 Jun 2007 10:51:38 +0000
parents 9ed365f4cbc8
children df1e2f0ef627
comparison
equal deleted inserted replaced
30:9a00ac84004c 31:3956bb7ff93b
190 | | ``v`` | Use one letter for short wall (generic) time, four for | 190 | | ``v`` | Use one letter for short wall (generic) time, four for |
191 | | | long wall time. | 191 | | | long wall time. |
192 +----------+--------+--------------------------------------------------------+ 192 +----------+--------+--------------------------------------------------------+
193 193
194 194
195 Time-zone Support
196 -----------------
197
198 Many of the verbose default time formats include the time-zone, but the
199 time-zone is not by default available for the Python ``datetime`` and ``time``
200 objects. The standard library includes only the abstract ``tzinfo`` class,
201 which you need appropriate implementations for to actually use in your
202 application. Babel includes a ``tzinfo`` implementation for UTC (Universal
203 Time). For actual time-zones, it is strongly recommended that you use the
204 third-party package `pytz`_, which includes the definitions of practically all
205 of the time-zones used on the world, as well as important functions for
206 reliably converting from UTC to local time, and vice versa::
207
208 >>> from datetime import time
209 >>> t = time(15, 30)
210
211 >>> from pytz import timezone
212 >>> cet = timezone('Europe/Berlin')
213 >>> format_time(t, 'H:mm Z', tzinfo=cet, locale='de_DE')
214 u'15:30 +0100'
215
216 The recommended approach to deal with different time-zones in a Python
217 application is to always use UTC internally, and only convert from/to the users
218 time-zone when accepting user input and displaying date/time data, respectively.
219
220 .. _`pytz`: http://pytz.sourceforge.net/
221
222
223
195 Parsing Dates 224 Parsing Dates
196 ------------- 225 -------------
197 226
198 Babel can also parse date and time information in a locale-sensitive manner:: 227 Babel can also parse date and time information in a locale-sensitive manner::
199 228
Copyright (C) 2012-2017 Edgewall Software