The Timedelta__python of the Python datetime module

Source: Internet
Author: User
Tags timedelta

Timedalte is an object in DateTime that represents the difference constructor for two times: Datetime.timedelta (days=0, seconds=0, microseconds=0, Milliseconds=0, Minutes=0, Hours=0, weeks=0)
Where the arguments are optional, the default value is 0

The following should be common sense, and almost everyone knows:


1 millisecond = 1000 microseconds
1 minute = seconds
1 hour = 3600 seconds

1 week = 7 days


In constructors, the range of parameter values is as follows:


0 <= microseconds < 1000000
0 <= seconds < 3600*24 (the number of seconds in one day)
-999999999 <= days <= 999999999


Timedalte has three read-only properties:


Timedelta.min: Negative number of the maximum time difference, equivalent to Timedelta (-999999999).
Timedelta.max: The maximum time difference of a positive number, equivalent to Timedelta (days=999999999, hours=23, minutes=59, seconds=59, microseconds=999999).

Timedelta.resolution: The minimum difference of two time is equivalent to Timedelta (Microseconds=1).


Three read-only property instances:

From datetime import Date,timedelta
print (Timedelta.max); #999999999 days, 23:59:59.999999
print ( days=999999999, hours=23, minutes=59, seconds=59, microseconds=999999); #999999999 days, 23:59:59.999999

print ( timedelta.min); #-999999999 days, 0:00:00
print (Timedelta ( -999999999)); #-999999999 days, 0:00:00

print ( timedelta.resolution); #0:00:00.000001
print (Timedelta (Microseconds=1)); #0:00:00.000001

Timedelta.total_seconds () Method: Returns the value of the time difference in seconds


Examples of the above:

From datetime import Datetime,date,timedelta now
= DateTime.Now ();
NextDay = Now + timedelta (days = 1), #增加一天后的时间
Nextsecond = Now + timedelta (seconds = 1), #增加一秒后的时间
span  = Now -NextDay #获取时间差对象
print (now);
Print (nextday);
Print (nextsecond);
Print (Span.total_seconds ()); #获取时间差 in seconds

The above to learn to tidy up a bit, if there is a mistake, please correct me. Thank you

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.