? ? ? ?之前有關于時間數據處理相關的工作我大都是使用time或者是datetime模塊來進行的,今天發現了一個非常好用的時間數據處理分析的模塊arrow,能夠很方便地完成一些時間計算等等,詳細的內容就不多說了,我使用了一些arrow提供的功能,都滿足了我工作中的需求,下面簡單給出來一些實踐例子,以及官方文檔地址在這里。
? ? ? ?下面是具體的實踐內容:
#!usr/bin/env python
#encoding:utf-8
from __future__ import division
'''
__Author__:沂水寒城
功能: Python日期轉換模塊arrow實踐使用
官方文檔地址: https://arrow.readthedocs.io/en/latest/
'''
import sys
import arrow
reload(sys)
sys.setdefaultencoding('utf-8')
#轉化為UTC時間【當前時間】
utc = arrow.utcnow()
print 'utc: ',utc
#轉化為UTC時間【倒退一小時】
utc = utc.replace(hours=-1)
print 'utc: ',utc
#轉化為UTC時間【前進4小時40分】
utc=utc.replace(hour=4,minute=40)
print 'utc: ',utc
#轉化為UTC時間【前進3周】
utc=utc.shift(weeks=+3)
print 'utc: ',utc
#轉化為當地時間【太平洋時間】
local = utc.to('US/Pacific')
print 'local: ',local
print arrow.get('2013-05-11T21:23:58.970460+00:00')
#轉化為當地時間戳
tmp=local.timestamp
print 'timestamp: ',tmp
#轉化為當地格式化時間
tmp=local.format()
print 'format: ',tmp
#轉化為當地格式化時間【指定格式化時間格式標準】
tmp=local.format('YYYY-MM-DD HH:mm:ss ZZ')
print 'format2: ',tmp
#轉化為人類語言的時間
human=local.humanize()
print 'human: ',human
#轉化為人類語言的時間【指定語言為韓國語】
human=local.humanize(locale='ko_kr')
print 'human: ',human
? ? ? ? ?結果如下:
utc: 2019-05-29T01:55:30.045000+00:00
utc: 2019-05-29T00:55:30.045000+00:00
utc: 2019-05-29T04:40:30.045000+00:00
utc: 2019-06-19T04:40:30.045000+00:00
local: 2019-06-18T21:40:30.045000-07:00
2013-05-11T21:23:58.970460+00:00
timestamp: 1560919230
format: 2019-06-18 21:40:30-07:00
format2: 2019-06-18 21:40:30 -07:00
human: in 21 days
human: 21? ?
[Finished in 0.3s]
? ? ? ? 記錄一下!
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
