python基礎===pendulum '''Python datetimes made easy.'''

來源:互聯網
上載者:User

標籤:local   party   last   tran   cond   mes   調用   less   nbsp   

https://pypi.python.org/pypi/pendulum

 

Pendulum的一大優勢是內嵌式取代Python的datetime類,可以輕易地將它整合進已有代碼,並且只在需要的時候才進行調用。作者精心調校了時區,確保時區準確,還讓每個執行個體都對時區敏感,預設使用UTC。還有就是提供了擴充的timedelta,使datetime計算更加容易。

與現有的其他庫不同,它提供了一個可預測行為的API,這樣就可以知道後面會發生什麼。如果你正開發使用datetimes的複雜項目,這個庫能讓你更輕鬆!想要瞭解更多,請查閱文檔。

>>> import pendulum>>> now_in_paris = pendulum.now(‘Europe/Paris‘)>>> now_in_paris‘2016-07-04T00:49:58.502116+02:00‘# Seamless timezone switching>>> now_in_paris.in_timezone(‘UTC‘)‘2016-07-03T22:49:58.502116+00:00‘>>> tomorrow = pendulum.now().add(days=1)>>> last_week = pendulum.now().subtract(weeks=1)>>> if pendulum.now().is_weekend():...     print(‘Party!‘)‘Party!‘>>> past = pendulum.now().subtract(minutes=2)>>> past.diff_for_humans()>>> ‘2 minutes ago‘>>> delta = past - last_week>>> delta.hours23>>> delta.in_words(locale=‘en‘)‘6 days 23 hours 58 minutes‘# Proper handling of datetime normalization>>> pendulum.create(2013, 3, 31, 2, 30, 0, 0, ‘Europe/Paris‘)‘2013-03-31T03:30:00+02:00‘ # 2:30 does not exist (Skipped time)# Proper handling of dst transitions>>> just_before = pendulum.create(2013, 3, 31, 1, 59, 59, 999999, ‘Europe/Paris‘)‘2013-03-31T01:59:59.999999+01:00‘>>> just_before.add(microseconds=1)‘2013-03-31T03:00:00+02:00‘

 

python基礎===pendulum '''Python datetimes made easy.'''

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.