Chapter XV: internationalization and localization -locale: cultural localization API- date and time

15.2.5 The date and time
is another important aspect of localized date and time format.

import locale
import time

sample_locales = [
    ('USA','en_US'),
    ('France','fr_FR'),
    ('Spain','es_ES'),
    ('Portugal','pt_PT'),
    ('Poland','pl_PL'),
    ]

for name,loc in sample_locales:
    locale.setlocale(locale.LC_ALL,loc)
    format = locale.nl_langinfo(locale.D_T_FMT)
    print('{:>10}: {}'.format(name,time.strftime(format)))

This example uses locale date format string to print the current date and time.

Guess you like

Origin blog.csdn.net/weixin_43193719/article/details/94833854