久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

    • <bdo id='xp1Hz'></bdo><ul id='xp1Hz'></ul>

  1. <legend id='xp1Hz'><style id='xp1Hz'><dir id='xp1Hz'><q id='xp1Hz'></q></dir></style></legend>
    <i id='xp1Hz'><tr id='xp1Hz'><dt id='xp1Hz'><q id='xp1Hz'><span id='xp1Hz'><b id='xp1Hz'><form id='xp1Hz'><ins id='xp1Hz'></ins><ul id='xp1Hz'></ul><sub id='xp1Hz'></sub></form><legend id='xp1Hz'></legend><bdo id='xp1Hz'><pre id='xp1Hz'><center id='xp1Hz'></center></pre></bdo></b><th id='xp1Hz'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='xp1Hz'><tfoot id='xp1Hz'></tfoot><dl id='xp1Hz'><fieldset id='xp1Hz'></fieldset></dl></div>
    <tfoot id='xp1Hz'></tfoot>

    <small id='xp1Hz'></small><noframes id='xp1Hz'>

      如何在python中顯示區域設置敏感時間格式而無需

      How to display locale sensitive time format without seconds in python(如何在python中顯示區域設置敏感時間格式而無需秒)
      <tfoot id='LQqbb'></tfoot>

      <legend id='LQqbb'><style id='LQqbb'><dir id='LQqbb'><q id='LQqbb'></q></dir></style></legend>
      • <bdo id='LQqbb'></bdo><ul id='LQqbb'></ul>

        1. <small id='LQqbb'></small><noframes id='LQqbb'>

                  <tbody id='LQqbb'></tbody>
                <i id='LQqbb'><tr id='LQqbb'><dt id='LQqbb'><q id='LQqbb'><span id='LQqbb'><b id='LQqbb'><form id='LQqbb'><ins id='LQqbb'></ins><ul id='LQqbb'></ul><sub id='LQqbb'></sub></form><legend id='LQqbb'></legend><bdo id='LQqbb'><pre id='LQqbb'><center id='LQqbb'></center></pre></bdo></b><th id='LQqbb'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='LQqbb'><tfoot id='LQqbb'></tfoot><dl id='LQqbb'><fieldset id='LQqbb'></fieldset></dl></div>

                本文介紹了如何在python中顯示區域設置敏感時間格式而無需秒的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我可以使用 strftime('%X') 輸出區域敏感的時間格式,但這總是包括秒.我如何在沒有秒的情況下顯示這種時間格式?

                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?

                >>> import locale
                >>> import datetime
                >>> locale.setlocale(locale.LC_ALL, 'en_IE.utf-8')
                'en_IE.utf-8'
                >>> print datetime.datetime.now().strftime('%X')
                12:22:43
                >>> locale.setlocale(locale.LC_ALL, 'zh_TW.utf-8')
                'zh_TW.utf-8'
                >>> print datetime.datetime.now().strftime('%X')
                12時22分58秒
                

                我能想到的唯一方法是嘗試解析 locale.nl_langinfo(locale.T_FMT) 的輸出并去除秒位,但這會帶來自己的詭計.

                The only way I can think of doing this is attempting to parse the output of locale.nl_langinfo(locale.T_FMT) and strip out the seconds bit, but that brings it's own trickery.

                >>> print locale.nl_langinfo(locale.T_FMT)
                %H時%M分%S秒
                >>> locale.setlocale(locale.LC_ALL, 'en_IE.utf-8')
                'en_IE.utf-8'
                >>> print locale.nl_langinfo(locale.T_FMT)
                %T
                

                <小時>

                解決方案:

                (基于pixelbeat的回答.)


                Solution:

                (Based on pixelbeat's answer.)

                # -*- coding: utf-8 -*-
                import locale
                def locale_time(t, show_seconds=False):
                    if show_seconds:
                        return t.strftime('%X')
                    replacement_fmts = [
                        (u'.%S', u''),
                        (u':%S', u''),
                        (u',%S', u''),
                        (u':%OS', ''),
                        (u'?????%S', u''),
                        (u' %S?', u''),
                        (u'%S秒', u''),
                        (u'%r', '%I:%M %p'),
                        (u'%t', '%H:%M'),
                        (u'%T', '%H:%M')
                    ]
                    enc=locale.getpreferredencoding(do_setlocale=False)
                    t_fmt = locale.nl_langinfo(locale.T_FMT).decode(enc)
                    for fmt in replacement_fmts:
                        new_t_fmt = t_fmt.replace(*fmt)
                        if new_t_fmt != t_fmt:
                            return t.strftime(new_t_fmt.encode(enc))
                    return t.strftime(t_fmt.encode(enc)
                

                用法:

                >>> locale.setlocale(locale.LC_ALL, 'en_IE.utf-8')
                'en_IE.utf-8'
                >>> print locale_time(t)
                15:47
                >>> locale.setlocale(locale.LC_ALL, 'zh_TW.utf-8')
                'zh_TW.utf-8'
                >>> print locale_time(t)
                15時47分
                

                推薦答案

                我會建議對返回的 T_FMT 進行特殊封裝,因為實際上沒有那么多需要考慮:

                I would suggest special casing the returned T_FMT as there aren't that many to consider really:

                $ for l in $(locale -a | grep utf8); do locale | cut -d= -f1 | LANG=$l xargs locale -kc | grep ^t_fmt=; done | sort -u
                
                t_fmt="%H:%M:%S"
                t_fmt="%H.%M.%S"
                t_fmt="%H? %M? %S?"
                t_fmt="??????%H?????%M?????%S"
                t_fmt="%H時%M分%S秒"
                t_fmt="%H時%M分%S秒 %Z"
                t_fmt="%H時%M分%S秒"
                t_fmt="%I.%M.%S %p"
                t_fmt="%I:%M:%S  %Z"
                t_fmt="%I:%M:%S %Z"
                t_fmt="%I.%M.%S. %Z"
                t_fmt="%I時%M分%S秒 %Z"
                t_fmt="kl. %H.%M %z"
                t_fmt="%k,%M,%S"
                t_fmt="%k:%M:%S"
                t_fmt="%l:%M:%S"
                t_fmt="%OH:%OM:%OS"
                t_fmt="%OI:%OM:%OS %p"
                t_fmt="%p%I.%M.%S %Z"
                t_fmt="%r"
                t_fmt="%t"
                t_fmt="%T"
                t_fmt="%Z %I:%M:%S "
                

                這篇關于如何在python中顯示區域設置敏感時間格式而無需秒的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to make a discord bot that gives roles in Python?(如何制作一個在 Python 中提供角色的不和諧機器人?)
                Discord bot isn#39;t responding to commands(Discord 機器人沒有響應命令)
                Can you Get the quot;About mequot; feature on Discord bot#39;s? (Discord.py)(你能得到“關于我嗎?Discord 機器人的功能?(不和諧.py))
                message.channel.id Discord PY(message.channel.id Discord PY)
                How do I host my discord.py bot on heroku?(如何在 heroku 上托管我的 discord.py 機器人?)
                discord.py - Automaticaly Change an Role Color(discord.py - 自動更改角色顏色)
                • <bdo id='Nzp7L'></bdo><ul id='Nzp7L'></ul>

                    <small id='Nzp7L'></small><noframes id='Nzp7L'>

                  1. <i id='Nzp7L'><tr id='Nzp7L'><dt id='Nzp7L'><q id='Nzp7L'><span id='Nzp7L'><b id='Nzp7L'><form id='Nzp7L'><ins id='Nzp7L'></ins><ul id='Nzp7L'></ul><sub id='Nzp7L'></sub></form><legend id='Nzp7L'></legend><bdo id='Nzp7L'><pre id='Nzp7L'><center id='Nzp7L'></center></pre></bdo></b><th id='Nzp7L'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Nzp7L'><tfoot id='Nzp7L'></tfoot><dl id='Nzp7L'><fieldset id='Nzp7L'></fieldset></dl></div>

                    <tfoot id='Nzp7L'></tfoot>
                  2. <legend id='Nzp7L'><style id='Nzp7L'><dir id='Nzp7L'><q id='Nzp7L'></q></dir></style></legend>
                            <tbody id='Nzp7L'></tbody>
                          主站蜘蛛池模板: 91精品国产91| 亚洲欧洲精品在线 | 国产精品亚洲成在人线 | 免费一区二区三区在线视频 | 全部免费毛片在线播放网站 | 97精品国产97久久久久久免费 | 99热国产在线播放 | 欧美精品一区在线发布 | a国产一区二区免费入口 | 国产片侵犯亲女视频播放 | 99久久精品免费看国产免费软件 | 91视频免费黄 | 日日爽 | 久久伊人影院 | 日韩成人专区 | 秋霞a级毛片在线看 | 成人免费毛片在线观看 | 亚洲精品乱码 | 亚洲福利在线观看 | 青青草网站在线观看 | 奇米av| 国产传媒在线观看 | 视频一区二区三区四区五区 | 丁香久久| 高清国产午夜精品久久久久久 | 亚洲精品日韩一区二区电影 | 国产一区精品 | h视频在线播放 | 九九热精品在线视频 | 亚洲人成人一区二区在线观看 | 欧美一区二区三区视频在线播放 | 看av片网站 | 蜜桃在线一区二区三区 | 亚洲视频国产 | 午夜视频一区二区 | 一级a性色生活片久久毛片 午夜精品在线观看 | www免费视频 | 青青草视频免费观看 | 91亚洲精华国产 | 一级女毛片 | 亚洲欧美视频一区 |