第十五章:国际化和本地化-locale:文化本地化API-日期和时间

15.2.5 日期和时间
本地化的另一个重要方面是日期和时间格式化。

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)))

这个例子使用本地化环境的日期格式化串来打印当前日期和时间。

猜你喜欢

转载自blog.csdn.net/weixin_43193719/article/details/94833854