詳解Django將秒轉(zhuǎn)換為xx天xx時(shí)xx分
Django將秒轉(zhuǎn)換為xx天xx時(shí)xx分,具體代碼如下所示:
from django.utils.translation import ngettext_lazy as _n def humanize_seconds(secs): a_day = 86400 an_hour = 3600 a_minute = 60 timetot = '' total_secs = secs if secs > a_day: # 60sec * 60min * 24hrs days = int(secs // a_day) # timetot += "{} {}".format(int(days), _('days')) timetot += _n('%(num)s day', '%(num)s days', days) % {'num': days} secs = secs - days * a_day if secs > an_hour: hrs = int(secs // an_hour) # timetot += " {} {}".format(int(hrs), _('hours')) timetot += ' ' timetot += _n('%(num)s hour', '%(num)s hours', hrs) % {'num': hrs} secs = secs - hrs * an_hour if secs > a_minute and total_secs < a_day: mins = int(secs // a_minute) timetot += ' ' timetot += _n('%(num)s minute', '%(num)s minutes', mins) % {'num': mins} secs = secs - mins * a_minute if secs > 0 and total_secs < an_hour: secs = int(secs) timetot += ' ' timetot += _n('%(num)s second', '%(num)s seconds', secs) % {'num': secs} return timetot if __name__ == "__main__": print(humanize_seconds(360200))
知識(shí)點(diǎn)擴(kuò)展:django 將model轉(zhuǎn)換為字典
from django.forms.models import model_to_dict from projects.models import ProjectInformation site = ProjectInformation.objects.get(id=6) dict = model_to_dict(site) dict {'CRFmethod': '', 'EDCprovider': '', 'acceptancenum': '', 'add_time': datetime.datetime(2017, 4, 20, 8, 4, 42, 751202, tzinfo=<UTC>), 'begindate': None, 'clinicalassis': '', 'clinicalnum': '', 'created_by': '', 'created_date': None, 'enddate': None, 'ethicsreviewdate': None, 'ethicsreviewpers': '', 'ethicsreviewres': '', 'ethicsreviewunit': '', 'id': 6, 'isimport': None, 'leaderunit': None, 'localcases': None, 'medicalequipment': '', 'mequipmenttype': '', 'multicenter': '', 'plannum': '', 'proenname': '愛上地方', 'proname': '打士大夫', 'prostatus': '', 'prosummary': '', 'protype': '打是否', 'regstudy': '是', 'reportdate': None, 'reportnum': '', 'reportversion': '', 'researchdesign': '', 'researchtype': '', 'responsible': '', 'studytype': '器械類', 'telephonenum': None, 'totalcases': None, 'treatmenttype': None, 'unitnum': None}
總結(jié)
以上所述是小編給大家介紹的Django將秒轉(zhuǎn)換為xx天xx時(shí)xx分,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!
如果你覺得本文對(duì)你有幫助,歡迎轉(zhuǎn)載,煩請(qǐng)注明出處,謝謝!
相關(guān)文章
Python數(shù)組拼接np.concatenate實(shí)現(xiàn)過程
這篇文章主要介紹了Python數(shù)組拼接np.concatenate實(shí)現(xiàn)過程,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-04-04python按比例隨機(jī)切分?jǐn)?shù)據(jù)的實(shí)現(xiàn)
這篇文章主要介紹了python按比例隨機(jī)切分?jǐn)?shù)據(jù)的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-07-07Window10+Python3.5安裝opencv的教程推薦
下面小編就為大家分享一篇Window10+Python3.5安裝opencv的教程推薦,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-04-04django API 中接口的互相調(diào)用實(shí)例
這篇文章主要介紹了django API 中接口的互相調(diào)用實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-04-04關(guān)于python3?opencv?圖像二值化的問題(cv2.adaptiveThreshold函數(shù))
這篇文章主要介紹了python3?opencv?圖像二值化cv2.adaptiveThreshold函數(shù)的相關(guān)知識(shí),結(jié)合示例代碼介紹了adaptiveThreshold方法的用法,需要的朋友可以參考下2022-04-04python實(shí)現(xiàn)機(jī)械分詞之逆向最大匹配算法代碼示例
這篇文章主要介紹了python實(shí)現(xiàn)機(jī)械分詞之逆向最大匹配算法代碼示例,具有一定借鑒價(jià)值,需要的朋友可以參考下。2017-12-12推薦10款最受Python開發(fā)者歡迎的Python IDE
這篇文章收集了一些對(duì)開發(fā)者非常有幫助的,最好的10款Python IDE,包括Vim,Eclipse with PyDev,Sublime Text,PyCharm等知明Python開發(fā)工具2018-09-09Python容器使用的5個(gè)技巧和2個(gè)誤區(qū)總結(jié)
在本篇文章里小編給大家整理的是關(guān)于Python容器使用的5個(gè)技巧和2個(gè)誤區(qū)的相關(guān)知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。2019-09-09Tensorflow2.1實(shí)現(xiàn)Fashion圖像分類示例詳解
這篇文章主要為大家介紹了Tensorflow2.1實(shí)現(xiàn)Fashion圖像分類示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-11-11