2006-05-02 09:31:56 +08:00
|
|
|
r"""
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, '')
|
|
|
|
''
|
|
|
|
>>> format(my_birthday, 'a')
|
|
|
|
'p.m.'
|
|
|
|
>>> format(my_birthday, 'A')
|
|
|
|
'PM'
|
2006-05-02 09:31:56 +08:00
|
|
|
>>> format(my_birthday, 'd')
|
|
|
|
'08'
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, 'j')
|
2006-05-02 09:31:56 +08:00
|
|
|
'8'
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, 'l')
|
2006-05-02 09:31:56 +08:00
|
|
|
'Sunday'
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, 'L')
|
|
|
|
'False'
|
|
|
|
>>> format(my_birthday, 'm')
|
|
|
|
'07'
|
|
|
|
>>> format(my_birthday, 'M')
|
|
|
|
'Jul'
|
|
|
|
>>> format(my_birthday, 'n')
|
|
|
|
'7'
|
|
|
|
>>> format(my_birthday, 'N')
|
|
|
|
'July'
|
|
|
|
>>> format(my_birthday, 'O')
|
|
|
|
'+0100'
|
|
|
|
>>> format(my_birthday, 'P')
|
|
|
|
'10 p.m.'
|
|
|
|
>>> format(my_birthday, 'r')
|
2006-05-02 09:31:56 +08:00
|
|
|
'Sun, 8 Jul 1979 22:00:00 +0100'
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, 's')
|
|
|
|
'00'
|
|
|
|
>>> format(my_birthday, 'S')
|
|
|
|
'th'
|
|
|
|
>>> format(my_birthday, 't')
|
2005-11-10 04:41:18 +08:00
|
|
|
'31'
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, 'T')
|
|
|
|
'CET'
|
|
|
|
>>> format(my_birthday, 'U')
|
2006-05-02 09:31:56 +08:00
|
|
|
'300531600'
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, 'w')
|
2006-05-02 09:31:56 +08:00
|
|
|
'0'
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, 'W')
|
|
|
|
'27'
|
|
|
|
>>> format(my_birthday, 'y')
|
|
|
|
'79'
|
|
|
|
>>> format(my_birthday, 'Y')
|
|
|
|
'1979'
|
|
|
|
>>> format(my_birthday, 'z')
|
2006-05-02 09:31:56 +08:00
|
|
|
'189'
|
2005-10-23 05:37:59 +08:00
|
|
|
>>> format(my_birthday, 'Z')
|
|
|
|
'3600'
|
|
|
|
|
|
|
|
>>> format(summertime, 'I')
|
|
|
|
'1'
|
|
|
|
>>> format(summertime, 'O')
|
|
|
|
'+0200'
|
|
|
|
>>> format(wintertime, 'I')
|
|
|
|
'0'
|
|
|
|
>>> format(wintertime, 'O')
|
|
|
|
'+0100'
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
>>> format(my_birthday, r'Y z \C\E\T')
|
|
|
|
'1979 189 CET'
|
|
|
|
|
|
|
|
>>> format(my_birthday, r'jS o\f F')
|
|
|
|
'8th of July'
|
2005-10-23 05:37:59 +08:00
|
|
|
"""
|
|
|
|
|
2005-11-10 04:36:23 +08:00
|
|
|
from django.utils import dateformat, translation
|
2005-10-23 05:37:59 +08:00
|
|
|
import datetime, os, time
|
|
|
|
|
2005-11-10 04:36:23 +08:00
|
|
|
format = dateformat.format
|
2005-10-23 05:37:59 +08:00
|
|
|
os.environ['TZ'] = 'Europe/Copenhagen'
|
2005-11-10 04:36:23 +08:00
|
|
|
translation.activate('en-us')
|
|
|
|
|
2005-10-23 05:37:59 +08:00
|
|
|
time.tzset()
|
|
|
|
|
2006-05-02 09:31:56 +08:00
|
|
|
my_birthday = datetime.datetime(1979, 7, 8, 22, 00)
|
2005-10-23 05:37:59 +08:00
|
|
|
summertime = datetime.datetime(2005, 10, 30, 1, 00)
|
|
|
|
wintertime = datetime.datetime(2005, 10, 30, 4, 00)
|