How to display locale sensitive time format without seconds in python

前端 未结 4 456
清歌不尽
清歌不尽 2020-12-20 12:38

I can output a locale sensitive time format using strftime(\'%X\'), but this always includes seconds. How might I display this time format without seconds?

4条回答
  •  再見小時候
    2020-12-20 13:21

    Consider ICU, and pyICU.

    >>> from icu import *
    >>> locale = Locale('en_US')
    >>> dtpg = DateTimePatternGenerator.createInstance(locale)
    >>> pattern = dtpg.getBestPattern('hm a')             
    >>> sdf = SimpleDateFormat(pattern, locale)           
    >>> sdf.format(1507059935.0)                  
    u'12:34 PM'
    >>> locale = Locale('de_DE')
    >>> dtpg = DateTimePatternGenerator.createInstance(locale)
    >>> pattern = dtpg.getBestPattern('hm a')             
    >>> sdf = SimpleDateFormat(pattern, locale)            
    >>> sdf.format(1507059935.0)                   
    u'12:34 nachm.'
    

提交回复
热议问题