The comparison method of DateTime in Python uses

Source: Internet
Author: User
Tags timedelta

The datetime module in Python is a powerful, but complex, module that deals with time-related content.
The code is used to find the timestamp from MySQL and the current time comparison, the method of finding the difference

Import datetime
Lasttime=a.get_last_timestamp (sid=40) [ -1]["Last_time"] #取到timestamp
Delta = datetime.datetime.now ()-lasttime #使用datetime. DateTime.Now () Gets the current time and then asks for a difference

If Delta > Datetime.timedelta (minutes=8): #如果时间差大于 8 minutes, (if 8 hours is hours=8, if 8 seconds is seconds=8)
.....

#datetime. Timedelta () This method is quite special, and the explanation for this class in python.org is:
Class DateTime. Timedelta ([days [, seconds [, microseconds [, milliseconds [, minutes [, hours [, weeks]]]

Parameters can be used together, such as Datetime.timedelta (HOURS=5,MINUTES=8,SECONDS=10), representing 5 hours 8 minutes 10 seconds
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.