Python base ===pendulum ' python datetimes made easy. '

Source: Internet
Author: User
Tags time zones

Https://pypi.python.org/pypi/pendulum

One of the great advantages of pendulum is that it replaces the Python datetime class in-line, and it can easily be integrated into existing code and invoked only when needed. The author carefully tuned the time zone to ensure that the time zone is accurate and that each instance is sensitive to time zones, using UTC by default. There is also an extended timedelta that makes datetime calculations easier.

Unlike an existing library, it provides an API for predictable behavior, so you know what happens later. If you are developing a complex project using DateTimes, this library will make it easier for you! To learn more, check out the documentation.

>>>ImportPendulum>>> 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)>>>ifPendulum.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 hours minutes'#Proper handling of datetime normalization>>> pendulum.create (2013, 3, 31, 2, 30, 0, 0,'Europe/paris')'2013-03-31t03:30:00+02:00' #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 base ===pendulum ' python datetimes made easy. '

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.