1
+ from datetime import datetime , timedelta
2
+ from time import time
3
+ from babel .dates import format_date , format_time , format_timedelta , format_datetime , get_timezone
4
+
5
+ print ('# Date format' )
6
+ d = datetime .utcnow ()
7
+ print ('English:' , format_date (d , locale = 'en' ))
8
+ print ('Danish (default)' , format_date (d , locale = 'da_DK' ))
9
+ print ('Danish (short)' , format_date (d , format = 'short' , locale = 'da_DK' ))
10
+ print ('Danish (medium)' , format_date (d , format = 'medium' , locale = 'da_DK' ))
11
+ print ('Danish (long)' , format_date (d , format = 'long' , locale = 'da_DK' ))
12
+ print ('Danish (full)' , format_date (d , format = 'full' , locale = 'da_DK' ))
13
+
14
+ print ('# Time format' )
15
+ t = time ()
16
+ print ('Danish' , format_time (t , locale = 'da' ))
17
+ print ('Danish (am/pm)' , format_time (t , 'h:mm a' , locale = 'da' ))
18
+ print ('Danish (secound)' , format_time (t , 'H:mm:ss' , locale = 'da' ))
19
+
20
+ print ('# Time Delta' )
21
+ delta = timedelta (days = 6 )
22
+ print ('USA:' , format_timedelta (delta , locale = 'en_US' ))
23
+ print ('Denmark:' , format_timedelta (delta , locale = 'da_DK' ))
24
+ print ('USA (min. month):' , format_timedelta (delta , granularity = 'month' , locale = 'en_US' ))
25
+
26
+ print ('# Time-zone' )
27
+ d = datetime .utcnow ()
28
+ print ('English:' , format_datetime (d , 'H:mm Z' , locale = 'en_US' ))
29
+ print ('USA/Eastern:' , format_datetime (d , 'H:mm Z' , tzinfo = get_timezone ('US/Eastern' ), locale = 'en_US' ))
30
+ print ('Europe/Copenhagen:' , format_datetime (d , 'H:mm Z' , tzinfo = get_timezone ('Europe/Copenhagen' ), locale = 'en_US' ))
0 commit comments