Làm cách nào để in số tuần trong python?

Mặc dù số học ngày và giờ được hỗ trợ, trọng tâm của việc triển khai là trích xuất thuộc tính hiệu quả để định dạng và thao tác đầu ra

Show

Xem thêm

Mô-đun
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
9

Các chức năng liên quan đến lịch chung

Mô-đun
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0

Thời gian truy cập và chuyển đổi

Mô-đun
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1

Múi giờ cụ thể đại diện cho cơ sở dữ liệu múi giờ IANA

ngày đóng gói

Thư viện của bên thứ ba với múi giờ mở rộng và hỗ trợ phân tích cú pháp

Đối tượng nhận thức và ngây thơ¶

Các đối tượng ngày và giờ có thể được phân loại là "nhận biết" hoặc "ngây thơ" tùy thuộc vào việc chúng có bao gồm thông tin múi giờ hay không

Với kiến ​​thức đầy đủ về các điều chỉnh thời gian chính trị và thuật toán hiện hành, chẳng hạn như múi giờ và thông tin về thời gian tiết kiệm ánh sáng ban ngày, một đối tượng nhận biết có thể định vị chính nó so với các đối tượng nhận biết khác. Một đối tượng nhận thức đại diện cho một thời điểm cụ thể không thể giải thích được. 1

Một đối tượng ngây thơ không chứa đủ thông tin để định vị chính nó một cách rõ ràng so với các đối tượng ngày/giờ khác. Việc một đối tượng ngây thơ đại diện cho Giờ phối hợp quốc tế (UTC), giờ địa phương hay thời gian ở một số múi giờ khác hoàn toàn phụ thuộc vào chương trình, giống như việc một số cụ thể đại diện cho mét, dặm hay khối lượng hay không là tùy thuộc vào chương trình. Các đối tượng ngây thơ dễ hiểu và dễ làm việc với cái giá phải trả là bỏ qua một số khía cạnh của thực tế

Đối với các ứng dụng yêu cầu các đối tượng nhận biết, các đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 có thuộc tính thông tin múi giờ tùy chọn,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4, có thể được đặt thành một thể hiện của một lớp con của lớp trừu tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4. Các đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 này nắm bắt thông tin về độ lệch so với thời gian UTC, tên múi giờ và liệu thời gian tiết kiệm ánh sáng ban ngày có hiệu lực hay không

Chỉ có một lớp

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 cụ thể, lớp
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8, được cung cấp bởi mô-đun
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7. Lớp
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 có thể đại diện cho các múi giờ đơn giản với độ lệch cố định từ UTC, chẳng hạn như chính UTC hoặc các múi giờ EST và EDT của Bắc Mỹ. Hỗ trợ các múi giờ ở mức độ chi tiết sâu hơn tùy thuộc vào ứng dụng. Các quy tắc điều chỉnh thời gian trên toàn thế giới mang tính chính trị hơn là hợp lý, thay đổi thường xuyên và không có tiêu chuẩn nào phù hợp cho mọi ứng dụng ngoài UTC

Hằng số¶

Mô-đun

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 xuất các hằng số sau

ngày giờ. THÁNG NĂM

Số năm nhỏ nhất được phép trong một đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 hoặc
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
34 là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
35

ngày giờ. MAX NĂM

Số năm lớn nhất được phép trong một đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 hoặc
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
38 là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
39

ngày giờ. UTC

Bí danh cho múi giờ UTC đơn lẻ

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
10

Mới trong phiên bản 3. 11

Các loại có sẵn¶

lớp ngày giờ. ngày

Một ngày ngây thơ được lý tưởng hóa, giả sử rằng lịch Gregorian hiện tại luôn có hiệu lực. Thuộc tính.

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
11,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
12 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
13

lớp ngày giờ. thời gian

Thời gian lý tưởng hóa, không phụ thuộc vào bất kỳ ngày cụ thể nào, giả sử rằng mỗi ngày có chính xác 24*60*60 giây. (Không có khái niệm “giây nhuận” ở đây. ) Thuộc tính.

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
15,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
16,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4

lớp ngày giờ. ngày giờ

Một sự kết hợp của một ngày và một thời gian. Thuộc tính.

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
11,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
12,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
13,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
15,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
16,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4

lớp ngày giờ. đồng hồ thời gian

Khoảng thời gian thể hiện sự khác biệt giữa hai phiên bản

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 hoặc
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 đối với độ phân giải micro giây

lớp ngày giờ. tzinfo

Một lớp cơ sở trừu tượng cho các đối tượng thông tin múi giờ. Chúng được sử dụng bởi các lớp

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 để cung cấp khái niệm điều chỉnh thời gian có thể tùy chỉnh (ví dụ: để tính múi giờ và/hoặc thời gian tiết kiệm ánh sáng ban ngày)

lớp ngày giờ. múi giờ

Một lớp triển khai lớp cơ sở trừu tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 dưới dạng phần bù cố định từ UTC

Mới trong phiên bản 3. 2

Các đối tượng của các loại này là bất biến

quan hệ phân lớp

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4

Tài sản chung¶

Các loại

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 có chung những đặc điểm này

  • Các đối tượng của các loại này là bất biến

  • Các đối tượng thuộc loại này có thể băm được, nghĩa là chúng có thể được sử dụng làm khóa từ điển

  • Các đối tượng thuộc loại này hỗ trợ tẩy hiệu quả thông qua mô-đun

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    97

Determining if an Object is Aware or Naive¶

Các đối tượng thuộc loại

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 luôn ngây thơ

Một đối tượng thuộc loại

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 hoặc
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 có thể nhận thức hoặc ngây thơ

Một đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 d nhận biết nếu cả hai điều sau đây đều đúng

  1. >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    402 không phải là
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    403

  2. >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    404 không trả lại
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    403

Mặt khác, d là ngây thơ

Một đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 t nhận biết được nếu cả hai điều kiện sau đều đúng

  1. >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    407 không phải là
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    403

  2. >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    409 không trả lại
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    403

Nếu không, t là ngây thơ

The distinction between aware and naive doesn’t apply to

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 objects

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411 Objects¶

A

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object represents a duration, the difference between two dates or times

class datetime. timedelta(days=0 , seconds=0 , microseconds=0 , milliseconds=0 , minutes=0 , hours=0 , weeks=0)

All arguments are optional and default to

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
414. Arguments may be integers or floats, and may be positive or negative

Only days, seconds and microseconds are stored internally. Arguments are converted to those units

  • A millisecond is converted to 1000 microseconds

  • A minute is converted to 60 seconds

  • An hour is converted to 3600 seconds

  • A week is converted to 7 days

and days, seconds and microseconds are then normalized so that the representation is unique, with

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    415

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    416 (the number of seconds in one day)

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    417

The following example illustrates how any arguments besides days, seconds and microseconds are “merged” and normalized into those three resulting attributes

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4

If any argument is a float and there are fractional microseconds, the fractional microseconds left over from all arguments are combined and their sum is rounded to the nearest microsecond using round-half-to-even tiebreaker. If no argument is a float, the conversion and normalization processes are exact (no information is lost)

If the normalized value of days lies outside the indicated range,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418 is raised

Note that normalization of negative values may be surprising at first. For example

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
2

Class attributes

đồng bằng thời gian. min

The most negative

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
420

timedelta. max

The most positive

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
422

timedelta. resolution

The smallest possible difference between non-equal

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 objects,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
424

Note that, because of normalization,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
425 >
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
426.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
427 is not representable as a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object

Instance attributes (read-only)

Attribute

Giá trị

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
429

Between -999999999 and 999999999 inclusive

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
430

Between 0 and 86399 inclusive

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
431

Between 0 and 999999 inclusive

Supported operations

Operation

Result

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
432

Sum of t2 and t3. Afterwards t1-t2 == t3 and t1-t3 == t2 are true. (1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
433

Difference of t2 and t3. Afterwards t1 == t2 - t3 and t2 == t1 + t3 are true. (1)(6)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
434

Delta multiplied by an integer. Afterwards t1 // i == t2 is true, provided

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
435

In general, t1 * i == t1 * (i-1) + t1 is true. (1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
436

Delta multiplied by a float. The result is rounded to the nearest multiple of timedelta. resolution using round-half-to-even

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
437

Division (3) of overall duration t2 by interval unit t3. Returns a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
438 object

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
439

Delta divided by a float or an int. The result is rounded to the nearest multiple of timedelta. resolution using round-half-to-even

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
440 or
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
441

The floor is computed and the remainder (if any) is thrown away. In the second case, an integer is returned. (3)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
442

The remainder is computed as a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object. (3)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
444

Tính thương và số dư.

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
445 (3) and
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
446. q is an integer and r is a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
448

Returns a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object with the same value. (2)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
450

tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411(-t1. ngày, -t1. giây, -t1. microseconds), and to t1* -1. (1)(4)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
452

tương đương với +t khi

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
453 và -t khi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
454. (2)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
455

Trả về một chuỗi ở dạng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
456, trong đó D là số âm cho số âm của
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
457. (5)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
458

Trả về một biểu diễn chuỗi của đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 dưới dạng lệnh gọi hàm tạo với các giá trị thuộc tính chính tắc

ghi chú

  1. Điều này là chính xác nhưng có thể tràn

  2. Điều này là chính xác và không thể tràn

  3. Chia cho 0 tăng

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    460

  4. -timedelta. max không thể biểu diễn dưới dạng đối tượng

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    411

  5. Biểu diễn chuỗi của đối tượng

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    411 được chuẩn hóa tương tự như biểu diễn bên trong của chúng. Điều này dẫn đến kết quả hơi bất thường đối với timedelta âm. Ví dụ

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17

  6. Biểu thức

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    463 sẽ luôn bằng biểu thức
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    464 trừ khi t3 bằng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    425;

Ngoài các hoạt động được liệt kê ở trên, các đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 hỗ trợ một số phép cộng và phép trừ với các đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 và
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 (xem bên dưới)

Đã thay đổi trong phiên bản 3. 2. Phép chia tầng và phép chia thực sự của một đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 cho một đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 khác hiện được hỗ trợ, cũng như các phép toán còn lại và hàm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
471. Phép chia và phép nhân thực của đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 với đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
438 hiện đã được hỗ trợ.

So sánh các đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 được hỗ trợ, với một số lưu ý

Các so sánh

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
475 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
476 luôn trả về một
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
477, bất kể loại đối tượng được so sánh

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False

Đối với tất cả các phép so sánh khác (chẳng hạn như

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
478 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
479), khi một đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 được so sánh với một đối tượng thuộc loại khác, thì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 được nâng lên

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'

Trong ngữ cảnh Boolean, một đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 được coi là đúng khi và chỉ khi nó không bằng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
483

Phương thức sơ thẩm

timedelta. total_seconds()

Return the total number of seconds contained in the duration. Equivalent to

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
484. For interval units other than seconds, use the division form directly (e. g.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
485)

Lưu ý rằng trong khoảng thời gian rất lớn (hơn 270 năm trên hầu hết các nền tảng), phương pháp này sẽ mất độ chính xác micro giây

Mới trong phiên bản 3. 2

Examples of usage. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411¶

An additional example of normalization

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
3

Ví dụ về số học

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32 Đối tượng¶

Một đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 đại diện cho một ngày (năm, tháng và ngày) trong lịch lý tưởng hóa, lịch Gregorian hiện tại được mở rộng vô thời hạn theo cả hai hướng

Ngày 1 tháng 1 của năm 1 được gọi là ngày 1, ngày 2 tháng 1 của năm 1 được gọi là ngày 2, v.v. 2

lớp ngày giờ. ngày(năm , tháng, day)

Tất cả các đối số là bắt buộc. Các đối số phải là số nguyên, trong các phạm vi sau

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    490

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    491

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    492

Nếu một đối số nằm ngoài các phạm vi đó được đưa ra, thì

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 được nêu ra

Other constructors, all class methods

phương thức lớp ngày. hôm nay()

Trả về ngày địa phương hiện tại

Điều này tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
494

phương thức lớp ngày. dấu thời gian từ(dấu thời gian)

Trả về ngày địa phương tương ứng với dấu thời gian POSIX, chẳng hạn như được trả về bởi

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
495

Điều này có thể tăng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418, nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi hàm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
497 của nền tảng C và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
498 khi lỗi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
497. Điều này thường bị giới hạn trong các năm từ 1970 đến 2038. Lưu ý rằng trên các hệ thống không phải POSIX bao gồm các giây nhuận trong khái niệm dấu thời gian của chúng, các giây nhuận sẽ bị bỏ qua bởi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
200

Đã thay đổi trong phiên bản 3. 3. Tăng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418 thay vì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 nếu dấu thời gian nằm ngoài phạm vi giá trị được hàm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
497 nền tảng C hỗ trợ. Tăng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
498 thay vì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 khi lỗi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
497.

phương thức lớp ngày. từ thứ tự(thứ tự)

Trả về ngày tương ứng với thứ tự Gregorian proleptic, trong đó ngày 1 tháng 1 của năm 1 có thứ tự 1

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 được nâng lên trừ khi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
208. Đối với bất kỳ ngày d,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
209

phương thức lớp ngày. fromisoformat(date_string)

Trả về một

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 tương ứng với một chuỗi ngày được cung cấp ở bất kỳ định dạng ISO 8601 hợp lệ nào, ngoại trừ các ngày thứ tự (e. g.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
211)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
71

Mới trong phiên bản 3. 7

Đã thay đổi trong phiên bản 3. 11. Trước đây, phương pháp này chỉ hỗ trợ định dạng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
212.

phương thức lớp ngày. từ dương lịch(năm , tuần, day)

Trả về một

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 tương ứng với ngày theo lịch ISO được chỉ định theo năm, tuần và ngày. Đây là nghịch đảo của hàm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
214

Mới trong phiên bản 3. 8

Class attributes

ngày. phút

Ngày đại diện sớm nhất,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
215

ngày. tối đa

Ngày đại diện mới nhất,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
216

ngày. độ phân giải

Sự khác biệt nhỏ nhất có thể giữa các đối tượng ngày không bằng nhau,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
217

Instance attributes (read-only)

ngày. năm

Bao gồm giữa

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
34 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
38

ngày. tháng

Từ 1 đến 12 bao gồm

ngày. ngày

Giữa 1 và số ngày trong tháng nhất định của năm nhất định

Supported operations

Operation

Result

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
220

date2 will be

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
221 days after date1. (1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
222

Tính date2 sao cho

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
223. (2)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
224

(3)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
225

date1 được coi là nhỏ hơn date2 khi date1 trước date2 về thời gian. (4)

ghi chú

  1. date2 được di chuyển về phía trước theo thời gian nếu

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    226 hoặc lùi lại nếu
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    227. Sau đó
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    228.
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    229 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    230 bị bỏ qua.
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    418 được nâng lên nếu
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    232 sẽ nhỏ hơn
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    34 hoặc lớn hơn
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    38

  2. >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    229 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    230 bị bỏ qua

  3. Điều này là chính xác và không thể tràn. múi giờ. giây và timedelta. micro giây là 0 và date2 + timedelta == date1 sau

  4. Nói cách khác,

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    225 khi và chỉ khi
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    238. So sánh ngày tăng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    481 nếu đối tượng so sánh khác không phải là đối tượng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    32. Tuy nhiên, thay vào đó,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    241 được trả về nếu đối tượng so sánh khác có thuộc tính
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    242. Móc này cung cấp cho các loại đối tượng ngày khác cơ hội thực hiện so sánh kiểu hỗn hợp. Nếu không, khi một đối tượng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    32 được so sánh với một đối tượng thuộc loại khác,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    481 được nâng lên trừ khi so sánh là
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    475 hoặc
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    476. Các trường hợp sau lần lượt trả về
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    247 hoặc
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    248

Trong ngữ cảnh Boolean, tất cả các đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 được coi là đúng

Phương thức sơ thẩm

ngày. thay thế(năm=chính mình. năm , tháng=chính mình. tháng , ngày=chính mình. ngày)

Trả về một ngày có cùng giá trị, ngoại trừ các tham số được cung cấp giá trị mới theo bất kỳ đối số từ khóa nào được chỉ định

Thí dụ

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
9

ngày. thời gian()

Trả lại một

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
250 chẳng hạn như trả về bởi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
251

Giờ, phút và giây là 0 và cờ DST là -1

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
252 tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
40

trong đó

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
253 là số ngày trong năm hiện tại bắt đầu bằng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
35 cho ngày 1 tháng 1

ngày. bình thường()

Trả về thứ tự Gregorian proleptic của ngày, trong đó ngày 1 tháng 1 của năm 1 có thứ tự 1. Đối với bất kỳ đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 d,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
209

ngày. ngày trong tuần()

Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 0 và Chủ nhật là 6. Ví dụ:

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
257, Thứ Tư. Xem thêm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
258

ngày. ngày trong tuần()

Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 1 và Chủ nhật là 7. Ví dụ:

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
259, Thứ Tư. Xem thêm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
260,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
261

ngày. isocalendar()

Trả về đối tượng tuple có tên có ba thành phần.

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
11,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
263 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
264.

Lịch ISO là một biến thể được sử dụng rộng rãi của lịch Gregorian. 3

Năm ISO bao gồm 52 hoặc 53 tuần đầy đủ và trong đó một tuần bắt đầu vào Thứ Hai và kết thúc vào Chủ nhật. Tuần đầu tiên của một năm ISO là tuần dương lịch (Gregorian) đầu tiên của một năm có ngày thứ Năm. Đây được gọi là tuần số 1 và năm ISO của ngày thứ Năm đó giống với năm Gregorian của nó

Ví dụ: năm 2004 bắt đầu vào Thứ Năm, vì vậy tuần đầu tiên của năm ISO 2004 bắt đầu vào Thứ Hai, ngày 29 tháng 12 năm 2003 và kết thúc vào Chủ Nhật, ngày 4 tháng 1 năm 2004

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
41

Đã thay đổi trong phiên bản 3. 9. Kết quả đã thay đổi từ một bộ thành bộ có tên .

ngày. isoformat()

Trả về một chuỗi đại diện cho ngày ở định dạng ISO 8601,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
212

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
42

ngày. __str__()

Đối với một ngày d,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
266 tương đương với
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
267

ngày. thời gian()

Trả về một chuỗi đại diện cho ngày

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
43

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
268 tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
44

trên các nền tảng có chức năng C

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
269 gốc (mà
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
270 gọi, nhưng mà
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
271 không gọi) phù hợp với tiêu chuẩn C

ngày. thời gian strf(định dạng)

Trả về một chuỗi đại diện cho ngày, được kiểm soát bởi một chuỗi định dạng rõ ràng. Mã định dạng đề cập đến giờ, phút hoặc giây sẽ thấy 0 giá trị. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime() và strptime() Hành vi .

ngày. __format__(định dạng)

Giống như

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
272. Điều này giúp có thể chỉ định chuỗi định dạng cho đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 trong ký tự chuỗi được định dạng và khi sử dụng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
274. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime() và strptime() Hành vi .

Ví dụ về cách sử dụng. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32¶

Ví dụ về đếm ngày đến một sự kiện

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
45

Thêm ví dụ về cách làm việc với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
46

>>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7 Đối tượng¶

Đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 là một đối tượng duy nhất chứa tất cả thông tin từ đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 và đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0

Giống như một đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 giả sử lịch Gregorian hiện tại được mở rộng theo cả hai hướng;

Hàm tạo

lớp ngày giờ. ngày giờ(năm , tháng, day, hour=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0)

Các đối số năm, tháng và ngày là bắt buộc. tzinfo may be

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, or an instance of a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass. Các đối số còn lại phải là số nguyên trong các phạm vi sau

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    490,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    491,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    492,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    290,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    291,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    292,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    293,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    294

Nếu một đối số nằm ngoài các phạm vi đó được đưa ra, thì

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 được nêu ra

Mới trong phiên bản 3. 6. Đã thêm đối số

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
296.

Other constructors, all class methods

phương thức lớp ngày giờ. hôm nay()

Trả về ngày giờ địa phương hiện tại, với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403

Tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
47

Xem thêm

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
299,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
200

Phương thức này có chức năng tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
299, nhưng không có tham số
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1702

phương thức lớp ngày giờ. bây giờ(tz=Không)

Trả về ngày và giờ địa phương hiện tại

Nếu đối số tùy chọn tz là

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 hoặc không được chỉ định, thì điều này giống như
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1704, nhưng, nếu có thể, cung cấp độ chính xác cao hơn mức có thể nhận được khi đi qua dấu thời gian
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
495 (ví dụ: điều này có thể thực hiện được trên các nền tảng cung cấp hàm C
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1706)

Nếu tz không phải là

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, thì nó phải là một thể hiện của lớp con
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 và ngày giờ hiện tại được chuyển đổi thành múi giờ của tz

Chức năng này được ưa thích hơn

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1704 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1710

phương thức lớp ngày giờ. utcnow()

Trả về ngày và giờ UTC hiện tại, với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403

Điều này giống như

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
299, nhưng trả về ngày và giờ UTC hiện tại, dưới dạng một đối tượng
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 ngây thơ. Có thể nhận được thời gian UTC hiện tại đã biết bằng cách gọi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1715. Xem thêm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
299

Cảnh báo

Bởi vì các đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 ngây thơ được nhiều phương thức
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 coi là giờ địa phương, nên sử dụng thời gian nhận thức để biểu thị thời gian trong UTC. Như vậy, cách được đề xuất để tạo một đối tượng biểu thị thời gian hiện tại theo UTC là gọi số
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1715

phương thức lớp ngày giờ. dấu thời gian từ(dấu thời gian , tz=None)

Trả về ngày và giờ địa phương tương ứng với dấu thời gian POSIX, chẳng hạn như được trả về bởi

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
495. Nếu đối số tùy chọn tz là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 hoặc không được chỉ định, thì dấu thời gian được chuyển đổi thành ngày giờ địa phương của nền tảng và đối tượng
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 được trả về là ngây thơ

Nếu tz không phải là

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, thì nó phải là một thể hiện của lớp con
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 và dấu thời gian được chuyển đổi thành múi giờ của tz

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
200 có thể tăng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418, nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi các hàm C
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
497 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1728 của nền tảng và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
498 khi lỗi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
497 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1728. Điều này thường bị giới hạn trong các năm từ 1970 đến 2038. Lưu ý rằng trên các hệ thống không phải POSIX bao gồm các giây nhuận trong khái niệm dấu thời gian của chúng, các giây nhuận bị bỏ qua bởi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
200 và sau đó có thể có hai dấu thời gian khác nhau một giây mang lại các đối tượng
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 giống hệt nhau. Phương pháp này được ưa thích hơn
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1734

Đã thay đổi trong phiên bản 3. 3. Tăng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418 thay vì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi các hàm nền tảng C
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
497 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1728. Tăng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
498 thay vì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 khi lỗi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
497 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1728.

Đã thay đổi trong phiên bản 3. 6. ______7200 có thể trả về các phiên bản với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
296 được đặt thành 1.

phương thức lớp ngày giờ. utcfromtimestamp(dấu thời gian)

Trả về UTC

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 tương ứng với dấu thời gian POSIX, với
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403. (Đối tượng kết quả là ngây thơ. )

Điều này có thể tăng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418, nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi hàm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1728 của nền tảng C và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
498 khi lỗi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1728. Điều này thường bị giới hạn trong các năm từ 1970 đến 2038

To get an aware

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object, call
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
200

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
48

Trên nền tảng tuân thủ POSIX, nó tương đương với biểu thức sau

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
49

ngoại trừ công thức sau luôn hỗ trợ phạm vi năm đầy đủ. giữa

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
34 và bao gồm cả
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
38

Cảnh báo

Bởi vì các đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 ngây thơ được nhiều phương thức
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 coi là giờ địa phương, nên sử dụng thời gian nhận thức để biểu thị thời gian trong UTC. Do đó, cách được khuyến nghị để tạo một đối tượng đại diện cho một dấu thời gian cụ thể trong UTC là gọi số
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1758

Đã thay đổi trong phiên bản 3. 3. Tăng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418 thay vì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 nếu dấu thời gian nằm ngoài phạm vi giá trị được hàm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1728 nền tảng C hỗ trợ. Tăng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
498 thay vì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 khi lỗi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1728.

phương thức lớp ngày giờ. từ thứ tự(thứ tự)

Trả lại

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 tương ứng với thứ tự Gregorian proleptic, trong đó ngày 1 tháng 1 của năm 1 có thứ tự 1.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 được nâng lên trừ khi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1767. Giờ, phút, giây và micro giây của kết quả đều là 0 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403

phương thức lớp ngày giờ. kết hợp(ngày , thời gian . tzinfo, tzinfo=self.tzinfo)

Trả về một đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 mới có thành phần ngày bằng với đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 đã cho và có thành phần thời gian bằng với đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 đã cho. Nếu đối số tzinfo được cung cấp, giá trị của nó được sử dụng để đặt thuộc tính
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 của kết quả, nếu không thì thuộc tính
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 của đối số thời gian được sử dụng

Đối với bất kỳ đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 d,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1776. Nếu ngày là một đối tượng
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7, các thành phần thời gian và thuộc tính
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 của nó sẽ bị bỏ qua

Đã thay đổi trong phiên bản 3. 6. Đã thêm đối số tzinfo.

phương thức lớp ngày giờ. fromisoformat(date_string)

Trả lại một

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 tương ứng với một chuỗi ngày ở bất kỳ định dạng ISO 8601 hợp lệ nào, với các ngoại lệ sau

  1. Độ lệch múi giờ có thể có giây phân số

  2. Dấu phân cách

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    1780 có thể được thay thế bằng bất kỳ ký tự unicode nào

  3. Ngày thứ tự hiện không được hỗ trợ

  4. Giờ và phút phân số không được hỗ trợ

ví dụ

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
20

Mới trong phiên bản 3. 7

Đã thay đổi trong phiên bản 3. 11. Trước đây, phương pháp này chỉ hỗ trợ các định dạng có thể được phát ra bởi

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1781 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1782.

phương thức lớp ngày giờ. từ dương lịch(năm , tuần, day)

Trả về một

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 tương ứng với ngày theo lịch ISO được chỉ định theo năm, tuần và ngày. Các thành phần không phải ngày tháng của ngày giờ được điền bằng các giá trị mặc định bình thường của chúng. Đây là nghịch đảo của hàm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1784

Mới trong phiên bản 3. 8

phương thức lớp ngày giờ. strptime(date_string , định dạng)

Trả về một

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 tương ứng với date_string, được phân tích cú pháp theo định dạng

Điều này tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
21

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 is raised if the date_string and format can’t be parsed by
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1787 or if it returns a value which isn’t a time tuple. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime() và strptime() Hành vi .

Class attributes

ngày giờ. phút

Đại diện sớm nhất

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1789

ngày giờ. tối đa

Đại diện mới nhất

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1791

ngày giờ. độ phân giải

Sự khác biệt nhỏ nhất có thể giữa các đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 không bằng nhau,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
424

Instance attributes (read-only)

ngày giờ. năm

Bao gồm giữa

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
34 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
38

ngày giờ. tháng

Từ 1 đến 12 bao gồm

ngày giờ. ngày

Giữa 1 và số ngày trong tháng nhất định của năm nhất định

ngày giờ. giờ

Trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1796

ngày giờ. phút

Trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1797

ngày giờ. giây

Trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1797

ngày giờ. micro giây

Trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1799

ngày giờ. tzinfo

Đối tượng được truyền dưới dạng đối số tzinfo cho hàm tạo

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 nếu không có đối số nào được truyền

ngày giờ. gấp

Trong

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
02. Được sử dụng để phân biệt thời gian tường trong một khoảng thời gian lặp lại. (Một khoảng thời gian lặp lại xảy ra khi đồng hồ được lùi lại vào cuối giờ tiết kiệm ánh sáng ban ngày hoặc khi độ lệch UTC cho vùng hiện tại bị giảm vì lý do chính trị. ) Giá trị 0 (1) thể hiện sớm hơn (muộn hơn) của hai thời điểm có cùng biểu diễn thời gian tường

Mới trong phiên bản 3. 6

Supported operations

Operation

Result

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
03

(1)

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
04

(2)

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
05

(3)

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
06

So sánh

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 với
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7. (4)

  1. datetime2 là khoảng thời gian của timedelta bị xóa khỏi datetime1, tiến về phía trước nếu

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    221 > 0 hoặc lùi lại nếu
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    221 < 0. Kết quả có thuộc tính
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4 giống như dữ liệu thời gian đầu vào và datetime2 - datetime1 == timedelta sau.
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    418 được nâng lên nếu datetime2. năm sẽ nhỏ hơn
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    34 hoặc lớn hơn
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    38. Lưu ý rằng không có điều chỉnh múi giờ nào được thực hiện ngay cả khi đầu vào là một đối tượng nhận biết

  2. Tính datetime2 sao cho datetime2 + timedelta == datetime1. Ngoài ra, kết quả có thuộc tính

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4 giống như ngày giờ đầu vào và không có điều chỉnh múi giờ nào được thực hiện ngay cả khi đầu vào biết

  3. Phép trừ của một

    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 từ một
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 chỉ được xác định nếu cả hai toán hạng đều ngây thơ hoặc nếu cả hai đều biết. Nếu một người nhận thức được và người kia ngây thơ,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    481 được nâng lên

    Nếu cả hai đều ngây thơ hoặc cả hai đều biết và có cùng thuộc tính

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4, các thuộc tính
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4 sẽ bị bỏ qua và kết quả là một đối tượng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    411 t sao cho
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    22. Không có điều chỉnh múi giờ nào được thực hiện trong trường hợp này

    If both are aware and have different

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4 attributes,
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    24 acts as if a and b were first converted to naive UTC datetimes first. Kết quả là
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    25 ngoại trừ việc triển khai không bao giờ bị tràn

  4. datetime1 được coi là nhỏ hơn datetime2 khi datetime1 trước datetime2 về thời gian

    Nếu một người so sánh ngây thơ và người kia nhận thức được, thì

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    481 sẽ được nâng lên nếu cố gắng so sánh đơn hàng. Để so sánh bình đẳng, các trường hợp ngây thơ không bao giờ bằng các trường hợp nhận thức

    Nếu cả hai đối tượng so sánh đều biết và có cùng thuộc tính

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4, thuộc tính chung
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4 sẽ bị bỏ qua và thời gian dữ liệu cơ sở được so sánh. Nếu cả hai bộ so sánh đều nhận biết và có các thuộc tính
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4 khác nhau, thì các bộ so sánh trước tiên được điều chỉnh bằng cách trừ đi độ lệch UTC của chúng (thu được từ
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    30)

    Đã thay đổi trong phiên bản 3. 3. So sánh bình đẳng giữa các trường hợp

    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 nhận thức và ngây thơ không nâng cao
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    481.

    Ghi chú

    Để ngăn việc so sánh quay trở lại sơ đồ so sánh địa chỉ đối tượng mặc định, so sánh ngày giờ thường tăng

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    481 nếu đối tượng so sánh khác cũng không phải là đối tượng
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7. Tuy nhiên, thay vào đó,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    241 được trả về nếu đối tượng so sánh khác có thuộc tính
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    242. Móc này cung cấp cho các loại đối tượng ngày khác cơ hội thực hiện so sánh kiểu hỗn hợp. Nếu không, khi một đối tượng
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 được so sánh với một đối tượng thuộc loại khác,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    481 được nâng lên trừ khi so sánh là
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    475 hoặc
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    476. Các trường hợp sau lần lượt trả về
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    247 hoặc
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    248

Phương thức sơ thẩm

ngày giờ. date()

Return

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 object with same year, month and day

datetime. time()

Return

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object with same hour, minute, second, microsecond and fold.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 is
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403. See also method
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
47

Changed in version 3. 6. The fold value is copied to the returned

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object.

datetime. timetz()

Return

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object with same hour, minute, second, microsecond, fold, and tzinfo attributes. See also method
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
50

Changed in version 3. 6. The fold value is copied to the returned

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object.

datetime. replace(year=self. year , month=self. month , day=self. day , hour=self. hour , minute=self. minute , second=self. second , microsecond=self. microsecond , tzinfo=self. tzinfo , * , fold=0)

Return a datetime with the same attributes, except for those attributes given new values by whichever keyword arguments are specified. Note that

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
52 can be specified to create a naive datetime from an aware datetime with no conversion of date and time data

Mới trong phiên bản 3. 6. Đã thêm đối số

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
296.

datetime. astimezone(tz=None)

Return a

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object with new
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute tz, adjusting the date and time data so the result is the same UTC time as self, but in tz’s local time

If provided, tz must be an instance of a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass, and its
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 and
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 methods must not return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403. If self is naive, it is presumed to represent time in the system timezone

If called without arguments (or with

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
60) the system local timezone is assumed for the target timezone. The
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
61 attribute of the converted datetime instance will be set to an instance of
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 with the zone name and offset obtained from the OS

If

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
63 is tz,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
64 is equal to self. no adjustment of date or time data is performed. Else the result is local time in the timezone tz, representing the same UTC time as self. after
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
65,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
66 will have the same date and time data as
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
67

If you merely want to attach a time zone object tz to a datetime dt without adjustment of date and time data, use

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
68. If you merely want to remove the time zone object from an aware datetime dt without conversion of date and time data, use
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
69

Note that the default

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
70 method can be overridden in a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass to affect the result returned by
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
72. Ignoring error cases,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 acts like

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
22

Changed in version 3. 3. tz now can be omitted.

Changed in version 3. 6. Phương thức

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 hiện có thể được gọi trên các phiên bản ngây thơ được cho là đại diện cho giờ địa phương của hệ thống.

datetime. utcoffset()

If

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 is
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, returns
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, else returns
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
78, and raises an exception if the latter doesn’t return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 or a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object with magnitude less than one day

Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.

ngày giờ. dst()

Nếu

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, trả về
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, ngược lại trả về
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
84 và đưa ra một ngoại lệ nếu cái sau không trả về
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 hoặc một đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 có cường độ nhỏ hơn một ngày

Đã thay đổi trong phiên bản 3. 7. DST offset không bị giới hạn trong một số phút.

ngày giờ. tzname()

Nếu

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, trả về
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, ngược lại trả về
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
90, đưa ra một ngoại lệ nếu cái sau không trả về
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 hoặc một đối tượng chuỗi,

ngày giờ. thời gian()

Trả lại một

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
250 chẳng hạn như trả về bởi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
251

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
252 tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
23

trong đó

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
253 là số ngày trong năm hiện tại bắt đầu bằng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
35 cho ngày 1 tháng 1. Cờ
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
97 của kết quả được đặt theo phương pháp
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 hoặc
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 trả về
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
97 được đặt thành
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
04;

ngày giờ. utctimetuple()

Nếu

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 thể hiện d là ngây thơ, thì điều này giống với
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
252 ngoại trừ việc
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
97 bị buộc về 0 bất kể giá trị trả về của
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
13 là gì. DST không bao giờ có hiệu lực trong thời gian UTC

Nếu d biết, d được chuẩn hóa thành thời gian UTC, bằng cách trừ đi

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14 và trả về
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
250 cho thời gian chuẩn hóa.
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
97 buộc phải 0. Lưu ý rằng một
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418 có thể được nâng lên nếu d. năm là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
34 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
38 và điều chỉnh UTC vượt qua ranh giới năm

Cảnh báo

Bởi vì các đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 ngây thơ được nhiều phương thức
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 coi là giờ địa phương, nên sử dụng thời gian nhận biết để biểu thị thời gian trong UTC; . Nếu bạn có một
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 ngây thơ đại diện cho UTC, hãy sử dụng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
24 để làm cho nó biết, tại thời điểm đó bạn có thể sử dụng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
25

ngày giờ. bình thường()

Trả về thứ tự Gregorian proleptic của ngày. Giống như

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
26

ngày giờ. dấu thời gian()

Trả về dấu thời gian POSIX tương ứng với phiên bản

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7. Giá trị trả về là một
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
438 tương tự như giá trị được trả về bởi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
495

Các phiên bản

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 ngây thơ được giả định là đại diện cho giờ địa phương và phương pháp này dựa vào hàm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
31 của nền tảng để thực hiện chuyển đổi. Vì
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 hỗ trợ phạm vi giá trị rộng hơn so với
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
31 trên nhiều nền tảng nên phương pháp này có thể tăng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418 cho những thời điểm xa trong quá khứ hoặc xa trong tương lai

Đối với các trường hợp

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 đã biết, giá trị trả về được tính là

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
24

Mới trong phiên bản 3. 3

Đã thay đổi trong phiên bản 3. 6. Phương thức

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
36 sử dụng thuộc tính
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
296 để phân biệt thời gian trong một khoảng thời gian lặp lại.

Ghi chú

Không có phương pháp nào để lấy dấu thời gian POSIX trực tiếp từ một phiên bản

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 ngây thơ đại diện cho thời gian UTC. Nếu ứng dụng của bạn sử dụng quy ước này và múi giờ hệ thống của bạn không được đặt thành UTC, bạn có thể lấy dấu thời gian POSIX bằng cách cung cấp
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
39

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
25

hoặc bằng cách tính toán dấu thời gian trực tiếp

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
26

datetime. ngày trong tuần()

Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 0 và Chủ nhật là 6. Giống như

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
40. Xem thêm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
258

ngày giờ. isoweekday()

Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 1 và Chủ nhật là 7. Giống như

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
42. Xem thêm
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
260,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
261

ngày giờ. isocalendar()

Trả về một bộ có tên với ba thành phần.

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
11,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
263 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
264. Giống như
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
48.

ngày giờ. isoformat(sep=', timespec='auto')

Return a string representing the date and time in ISO 8601 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    49, if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is not 0

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    51, if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is 0

If

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 does not return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, a string is appended, giving the UTC offset

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    55, if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is not 0

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    57, if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is 0

ví dụ

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
27

The optional argument sep (default

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
59) is a one-character separator, placed between the date and time portions of the result. For example

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
28

The optional argument timespec specifies the number of additional components of the time to include (the default is

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
60). It can be one of the following

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    60. Same as
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    62 if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is 0, same as
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    64 otherwise

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    65. Include the
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    14 in the two-digit
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    67 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    68. Include
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    14 and
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    15 in
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    71 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    62. Include
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    14,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    15, and
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    16 in
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    76 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    77. Include full time, but truncate fractional second part to milliseconds.
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    78 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    64. Include full time in
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    80 format

Ghi chú

Excluded time components are truncated, not rounded

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 will be raised on an invalid timespec argument

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
29

New in version 3. 6. Added the timespec argument.

datetime. __str__()

For a

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 instance d,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
266 is equivalent to
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
84

datetime. ctime()

Return a string representing the date and time

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
170

The output string will not include time zone information, regardless of whether the input is aware or naive

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
268 tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
44

on platforms where the native C

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
269 function (which
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
270 invokes, but which
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
88 does not invoke) conforms to the C standard

datetime. strftime(format)

Return a string representing the date and time, controlled by an explicit format string. For a complete list of formatting directives, see strftime() and strptime() Behavior .

datetime. __format__(format)

Same as

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
89. This makes it possible to specify a format string for a
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object in formatted string literals and when using
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
274. For a complete list of formatting directives, see strftime() and strptime() Behavior .

Examples of Usage. >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7¶

Examples of working with

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 objects

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
172

The example below defines a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass capturing time zone information for Kabul, Afghanistan, which used +4 UTC until 1945 and then +4. 30 UTC thereafter

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
173

Usage of

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
95 from above

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
174

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0 Objects¶

A

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object represents a (local) time of day, independent of any particular day, and subject to adjustment via a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 object

class datetime. time(hour=0 , minute=0 , second=0 , microsecond=0 , tzinfo=None , * , fold=0)

All arguments are optional. tzinfo may be

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, or an instance of a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass. The remaining arguments must be integers in the following ranges

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    290,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    291,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    292,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    293,

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    294

If an argument outside those ranges is given,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 is raised. All default to
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
414 except tzinfo, which defaults to
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403

Class attributes

time. min

The earliest representable

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
310

time. max

The latest representable

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
312

time. resolution

The smallest possible difference between non-equal

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 objects,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
424, although note that arithmetic on
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 objects is not supported

Instance attributes (read-only)

time. hour

Trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1796

time. minute

Trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1797

time. second

Trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1797

time. microsecond

Trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1799

time. tzinfo

The object passed as the tzinfo argument to the

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 constructor, or
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 if none was passed

time. fold

Trong

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
02. Được sử dụng để phân biệt thời gian tường trong một khoảng thời gian lặp lại. (Một khoảng thời gian lặp lại xảy ra khi đồng hồ được lùi lại vào cuối giờ tiết kiệm ánh sáng ban ngày hoặc khi độ lệch UTC cho vùng hiện tại bị giảm vì lý do chính trị. ) Giá trị 0 (1) thể hiện sớm hơn (muộn hơn) của hai thời điểm có cùng biểu diễn thời gian tường

Mới trong phiên bản 3. 6

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 objects support comparison of
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 to
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0, where a is considered less than b when a precedes b in time. If one comparand is naive and the other is aware,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 is raised if an order comparison is attempted. For equality comparisons, naive instances are never equal to aware instances

If both comparands are aware, and have the same

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute, the common
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute is ignored and the base times are compared. If both comparands are aware and have different
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attributes, the comparands are first adjusted by subtracting their UTC offsets (obtained from
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
30). In order to stop mixed-type comparisons from falling back to the default comparison by object address, when a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object is compared to an object of a different type,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 is raised unless the comparison is
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
475 or
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
476. The latter cases return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
247 or
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
248, respectively

Changed in version 3. 3. Equality comparisons between aware and naive

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 instances don’t raise
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481.

In Boolean contexts, a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object is always considered to be true

Changed in version 3. 5. Before Python 3. 5, a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object was considered to be false if it represented midnight in UTC. This behavior was considered obscure and error-prone and has been removed in Python 3. 5. See bpo-13936 for full details.

Other constructor

classmethod time. fromisoformat(time_string)

Trả về một

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 tương ứng với một time_string ở bất kỳ định dạng ISO 8601 hợp lệ nào, với các ngoại lệ sau

  1. Độ lệch múi giờ có thể có giây phân số

  2. The leading

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    1780, normally required in cases where there may be ambiguity between a date and a time, is not required

  3. Fractional seconds may have any number of digits (anything beyond 6 will be truncated)

  4. Giờ và phút phân số không được hỗ trợ

ví dụ

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
175

Mới trong phiên bản 3. 7

Changed in version 3. 11. Previously, this method only supported formats that could be emitted by

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
343.

Phương thức sơ thẩm

time. replace(hour=self. hour , minute=self. minute , second=self. second , microsecond=self. microsecond , tzinfo=self. tzinfo , * , fold=0)

Return a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 with the same value, except for those attributes given new values by whichever keyword arguments are specified. Note that
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
52 can be specified to create a naive
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 from an aware
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0, without conversion of the time data

Mới trong phiên bản 3. 6. Đã thêm đối số

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
296.

time. isoformat(timespec='auto')

Return a string representing the time in ISO 8601 format, one of

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    80, if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is not 0

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    76, if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is 0

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    353, if
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    57 does not return
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    403

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    356, if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is 0 and
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    57 does not return
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    403

The optional argument timespec specifies the number of additional components of the time to include (the default is

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
60). It can be one of the following

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    60. Same as
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    62 if
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    17 is 0, same as
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    64 otherwise

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    65. Include the
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    14 in the two-digit
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    67 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    68. Include
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    14 and
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    15 in
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    71 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    62. Include
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    14,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    15, and
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    16 in
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    76 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    77. Include full time, but truncate fractional second part to milliseconds.
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    78 format

  • >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    64. Include full time in
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    80 format

Ghi chú

Excluded time components are truncated, not rounded

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 will be raised on an invalid timespec argument

Thí dụ

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
176

New in version 3. 6. Added the timespec argument.

time. __str__()

For a time t,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
455 is equivalent to
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
383

time. strftime(format)

Return a string representing the time, controlled by an explicit format string. For a complete list of formatting directives, see strftime() and strptime() Behavior .

time. __format__(format)

Same as

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
384. This makes it possible to specify a format string for a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object in formatted string literals and when using
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
274. For a complete list of formatting directives, see strftime() and strptime() Behavior .

time. utcoffset()

If

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 is
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, returns
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, else returns
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
390, and raises an exception if the latter doesn’t return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 or a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object with magnitude less than one day

Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.

time. dst()

If

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 is
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, returns
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, else returns
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
396, and raises an exception if the latter doesn’t return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, or a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object with magnitude less than one day

Đã thay đổi trong phiên bản 3. 7. DST offset không bị giới hạn trong một số phút.

time. tzname()

If

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 is
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, returns
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, else returns
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
102, or raises an exception if the latter doesn’t return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 or a string object

Examples of Usage. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0¶

Examples of working with a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
177

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 Objects¶

class datetime. tzinfo

This is an abstract base class, meaning that this class should not be instantiated directly. Define a subclass of

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 to capture information about a particular time zone

An instance of (a concrete subclass of)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 can be passed to the constructors for
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 and
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 objects. The latter objects view their attributes as being in local time, and the
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 object supports methods revealing offset of local time from UTC, the name of the time zone, and DST offset, all relative to a date or time object passed to them

You need to derive a concrete subclass, and (at least) supply implementations of the standard

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 methods needed by the
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 methods you use. The
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 module provides
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8, a simple concrete subclass of
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 which can represent timezones with fixed offset from UTC such as UTC itself or North American EST and EDT

Special requirement for pickling. A

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass must have an
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
118 method that can be called with no arguments, otherwise it can be pickled but possibly not unpickled again. This is a technical requirement that may be relaxed in the future

A concrete subclass of

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 may need to implement the following methods. Exactly which methods are needed depends on the uses made of aware
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 objects. If in doubt, simply implement all of them

tzinfo. utcoffset(dt)

Return offset of local time from UTC, as a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object that is positive east of UTC. If local time is west of UTC, this should be negative

This represents the total offset from UTC; for example, if a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 object represents both time zone and DST adjustments,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 should return their sum. If the UTC offset isn’t known, return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403. Else the value returned must be a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object strictly between
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
126 and
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
127 (the magnitude of the offset must be less than one day). Most implementations of
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 will probably look like one of these two

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
178

If

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 does not return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 should not return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 either

The default implementation of

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 raises
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
134

Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.

tzinfo. dst(dt)

Return the daylight saving time (DST) adjustment, as a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object or
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 if DST information isn’t known

Return

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
483 if DST is not in effect. If DST is in effect, return the offset as a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 object (see
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 for details). Note that DST offset, if applicable, has already been added to the UTC offset returned by
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
57, so there’s no need to consult
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 unless you’re interested in obtaining DST info separately. For example,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
25 calls its
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute’s
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 method to determine how the
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
97 flag should be set, and
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
70 calls
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 to account for DST changes when crossing time zones

An instance tz of a

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass that models both standard and daylight times must be consistent in this sense

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
149

must return the same result for every

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 dt with
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
151 For sane
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclasses, this expression yields the time zone’s “standard offset”, which should not depend on the date or the time, but only on geographic location. The implementation of
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
153 relies on this, but cannot detect violations; it’s the programmer’s responsibility to ensure it. If a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass cannot guarantee this, it may be able to override the default implementation of
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
70 to work correctly with
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 regardless

Most implementations of

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 will probably look like one of these two

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
179

or

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
0

The default implementation of

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 raises
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
134

Đã thay đổi trong phiên bản 3. 7. DST offset không bị giới hạn trong một số phút.

tzinfo. tzname(dt)

Return the time zone name corresponding to the

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object dt, as a string. Nothing about string names is defined by the
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 module, and there’s no requirement that it mean anything in particular. For example, “GMT”, “UTC”, “-500”, “-5. 00”, “EDT”, “US/Eastern”, “America/New York” đều là những câu trả lời hợp lệ. Return
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 if a string name isn’t known. Note that this is a method rather than a fixed string primarily because some
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclasses will wish to return different names depending on the specific value of dt passed, especially if the
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 class is accounting for daylight time

The default implementation of

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
165 raises
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
134

Các phương thức này được gọi bởi một đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 hoặc
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0, để đáp lại các phương thức cùng tên của chúng. A
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object passes itself as the argument, and a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 object passes
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 as the argument. A
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 subclass’s methods should therefore be prepared to accept a dt argument of
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403, or of class
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7

When

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 is passed, it’s up to the class designer to decide the best response. For example, returning
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403 is appropriate if the class wishes to say that time objects don’t participate in the
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 protocols. It may be more useful for
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
178 to return the standard UTC offset, as there is no other convention for discovering the standard offset

When a

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object is passed in response to a
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 method,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
181 is the same object as self.
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 methods can rely on this, unless user code calls
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 methods directly. The intent is that the
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 methods interpret dt as being in local time, and not need worry about objects in other timezones

Có thêm một phương thức

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 mà một lớp con có thể muốn ghi đè

tzinfo. từutc(dt)

Điều này được gọi từ triển khai

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
153 mặc định. Khi được gọi từ đó,
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
181 là chính nó và dữ liệu ngày và giờ của dt sẽ được xem là thể hiện thời gian UTC. Mục đích của
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
188 là điều chỉnh dữ liệu ngày và giờ, trả về một ngày giờ tương đương theo giờ địa phương của chính bạn

Hầu hết các lớp con của

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 sẽ có thể kế thừa triển khai
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
188 mặc định mà không gặp sự cố. Nó đủ mạnh để xử lý các múi giờ có độ lệch cố định và các múi giờ tính cả thời gian tiêu chuẩn và thời gian ban ngày, và cả thời gian sau ngay cả khi thời gian chuyển đổi DST khác nhau trong các năm khác nhau. Một ví dụ về múi giờ mà việc triển khai
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
188 mặc định có thể không xử lý chính xác trong mọi trường hợp là trường hợp mà phần bù tiêu chuẩn (từ UTC) phụ thuộc vào ngày và giờ cụ thể đã trôi qua, điều này có thể xảy ra vì lý do chính trị. Việc triển khai mặc định của
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
188 có thể không tạo ra kết quả như bạn muốn nếu kết quả là một trong những giờ diễn ra vào thời điểm bù trừ tiêu chuẩn thay đổi

Bỏ qua mã cho các trường hợp lỗi, việc triển khai

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
188 mặc định hoạt động như

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
1

Trong tệp

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
195 sau đây có một số ví dụ về lớp
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
2

Lưu ý rằng có những sự tinh tế không thể tránh khỏi hai lần mỗi năm trong phân lớp

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 cho cả thời gian tiêu chuẩn và thời gian ban ngày, tại các điểm chuyển tiếp DST. Để cụ thể, hãy xem xét Miền Đông Hoa Kỳ (UTC -0500), nơi EDT bắt đầu sau 1 phút. 59 (EST) vào Chủ nhật thứ hai của tháng 3 và kết thúc vào phút sau 1. 59 (EDT) vào Chủ nhật đầu tiên của tháng 11

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
3

Khi DST bắt đầu (dòng “bắt đầu”), đồng hồ treo tường địa phương nhảy từ 1. 59 đến 3. 00. Một bức tường thời gian của mẫu 2. MM không thực sự có ý nghĩa vào ngày đó, vì vậy

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
198 sẽ không mang lại kết quả với
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
199 vào ngày DST bắt đầu. Ví dụ: tại chuyển tiếp mùa xuân năm 2016, chúng tôi nhận được

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
4

Khi DST kết thúc (dòng “kết thúc”), có khả năng xảy ra sự cố tồi tệ hơn. có một giờ không thể đánh vần rõ ràng theo giờ địa phương. giờ cuối cùng của thời gian ban ngày. Ở phương Đông, đó là thời gian của mẫu 5. MM UTC vào ngày thời gian ban ngày kết thúc. Đồng hồ treo tường địa phương nhảy từ 1. 59 (thời gian ban ngày) trở lại 1. 00 (giờ chuẩn) lại. Giờ địa phương của mẫu 1. MM không rõ ràng.

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 bắt chước hành vi của đồng hồ địa phương bằng cách ánh xạ hai giờ UTC liền kề vào cùng một giờ địa phương sau đó. In the Eastern example, UTC times of the form 5. MM và 6. MM cả ánh xạ tới 1. MM khi được chuyển đổi thành Eastern, nhưng những lần trước đó thuộc tính
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
296 được đặt thành 0 và những lần sau thuộc tính này được đặt thành 1. Ví dụ: tại Fall back transition năm 2016, chúng tôi nhận được

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
5

Lưu ý rằng các trường hợp

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 chỉ khác nhau về giá trị của thuộc tính
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
296 được coi là bằng nhau khi so sánh

Các ứng dụng không thể chịu được sự mơ hồ về thời gian treo tường nên kiểm tra rõ ràng giá trị của thuộc tính

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
296 hoặc tránh sử dụng các lớp con
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 kết hợp;

Xem thêm

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1

Mô-đun

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 có lớp
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 cơ bản (để xử lý các giá trị bù cố định tùy ý từ UTC) và thuộc tính
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7111 của nó (một thể hiện múi giờ UTC)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1 đưa cơ sở dữ liệu múi giờ IANA (còn được gọi là cơ sở dữ liệu Olson) vào Python và việc sử dụng cơ sở dữ liệu này được khuyến nghị

Cơ sở dữ liệu múi giờ IANA

Cơ sở dữ liệu múi giờ (thường được gọi là tz, tzdata hoặc zoneinfo) chứa mã và dữ liệu biểu thị lịch sử giờ địa phương cho nhiều vị trí đại diện trên toàn cầu. Nó được cập nhật định kỳ để phản ánh những thay đổi do các cơ quan chính trị thực hiện đối với ranh giới múi giờ, độ lệch UTC và quy tắc tiết kiệm ánh sáng ban ngày

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 8 Đối tượng¶

Lớp

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 là một lớp con của
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4, mỗi phiên bản đại diện cho một múi giờ được xác định bởi phần bù cố định từ UTC

Các đối tượng của lớp này không thể được sử dụng để biểu diễn thông tin múi giờ ở những vị trí sử dụng các độ lệch khác nhau trong các ngày khác nhau trong năm hoặc nơi các thay đổi lịch sử đã được thực hiện đối với thời gian dân sự

lớp ngày giờ. múi giờ(độ lệch , tên=None)

Đối số offset phải được chỉ định là một đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 thể hiện sự khác biệt giữa giờ địa phương và UTC. Nó phải hoàn toàn nằm giữa
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
126 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
127, nếu không thì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 được nâng lên

Đối số tên là tùy chọn. Nếu được chỉ định, nó phải là một chuỗi sẽ được sử dụng làm giá trị được trả về bởi phương thức

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7120

Mới trong phiên bản 3. 2

Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.

múi giờ. utcoffset(dt)

Trả về giá trị cố định được chỉ định khi phiên bản

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 được tạo

Đối số dt bị bỏ qua. Giá trị trả về là một phiên bản

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 bằng với sự khác biệt giữa giờ địa phương và UTC

Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.

múi giờ. tzname(dt)

Trả về giá trị cố định được chỉ định khi phiên bản

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 được tạo

Nếu tên không được cung cấp trong hàm tạo, tên được trả về bởi

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7124 được tạo từ giá trị của
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7125 như sau. Nếu offset là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
483, tên là “UTC”, nếu không, nó là một chuỗi ở định dạng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7127, trong đó ± là dấu của
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7125, HH và MM lần lượt là hai chữ số của
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7129 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7130

Đã thay đổi trong phiên bản 3. 6. Tên được tạo từ

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7131 hiện là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7132 đơn giản, không phải
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7133.

múi giờ. dst(dt)

Always returns

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403

timezone. fromutc(dt)

Return

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7135. The dt argument must be an aware
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 instance, with
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 set to
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7138

Class attributes

timezone. utc

The UTC timezone,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7139

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7140 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7141 Behavior¶

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32,
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7, and
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 objects all support a
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7145 method, to create a string representing the time under the control of an explicit format string

Conversely, the

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7146 class method creates a
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object from a string representing a date and time and a corresponding format string

The table below provides a high-level comparison of

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7140 versus
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7150

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7151

Usage

Convert object to a string according to a given format

Parse a string into a

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object given a corresponding format

Type of method

Instance method

Class method

Method of

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32;
>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7;
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0

>>> from datetime import timedelta
>>> delta1 = timedelta(seconds=57)
>>> delta2 = timedelta(hours=25, seconds=2)
>>> delta2 != delta1
True
>>> delta2 == 5
False
7

Signature

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7145

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7158

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7140 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7141 Format Codes¶

The following is a list of all the format codes that the 1989 C standard requires, and these work on all platforms with a standard C implementation

Directive

Meaning

Example

Notes

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7161

Weekday as locale’s abbreviated name

Sun, Mon, …, Sat (en_US);

So, Mo, …, Sa (de_DE)

(1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7162

Weekday as locale’s full name

Chủ Nhật, Thứ Hai, …, Thứ Bảy (en_US);

Sonntag, Montag, …, Samstag (de_DE)

(1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7163

Ngày trong tuần dưới dạng số thập phân, trong đó 0 là Chủ nhật và 6 là Thứ bảy

0, 1, …, 6

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7164

Ngày trong tháng dưới dạng số thập phân không đệm

01, 02, …, 31

(9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7165

Tháng là tên viết tắt của ngôn ngữ

Tháng 1, Tháng 2, …, Tháng 12 (en_US);

Tháng 1, Tháng 2, …, Dez (de_DE)

(1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7166

Tháng là tên đầy đủ của ngôn ngữ

Tháng Giêng, Tháng Hai, …, Tháng Mười Hai (en_US);

Januar, Februar, …, Tháng mười hai (de_DE)

(1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7167

Tháng dưới dạng số thập phân không đệm

01, 02, …, 12

(9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7168

Năm không có thế kỷ dưới dạng số thập phân không đệm

00, 01, …, 99

(9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7169

Năm với thế kỷ dưới dạng số thập phân

0001, 0002, …, 2013, 2014, …, 9998, 9999

(2)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7170

Giờ (đồng hồ 24 giờ) dưới dạng số thập phân không đệm

00, 01, …, 23

(9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7171

Giờ (đồng hồ 12 giờ) dưới dạng số thập phân không đệm

01, 02, …, 12

(9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7172

Ngôn ngữ tương đương với AM hoặc PM

AM, PM (en_US);

sáng, chiều (de_DE)

(1), (3)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7173

Phút dưới dạng số thập phân không đệm

00, 01, …, 59

(9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7174

Thứ hai dưới dạng số thập phân không đệm

00, 01, …, 59

(4), (9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7175

Micro giây dưới dạng số thập phân, được đệm bằng 0 thành 6 chữ số

000000, 000001, …, 999999

(5)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7176

Phần bù UTC ở dạng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7177 (chuỗi trống nếu đối tượng là ngây thơ)

(trống), +0000, -0400, +1030, +063415, -030712. 345216

(6)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7178

Tên múi giờ (chuỗi trống nếu đối tượng ngây thơ)

(trống), UTC, GMT

(6)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7179

Ngày trong năm dưới dạng số thập phân không đệm

001, 002, …, 366

(9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7180

Số tuần của năm (Chủ nhật là ngày đầu tiên của tuần) dưới dạng số thập phân không đệm. Tất cả các ngày trong một năm mới trước Chủ nhật đầu tiên được coi là trong tuần 0

00, 01, …, 53

(7), (9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7181

Số tuần của năm (Thứ Hai là ngày đầu tiên của tuần) dưới dạng số thập phân không đệm. Tất cả các ngày trong năm mới trước ngày thứ Hai đầu tiên được coi là trong tuần 0

00, 01, …, 53

(7), (9)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7182

Đại diện ngày và giờ thích hợp của ngôn ngữ

Thứ ba 16 tháng 8 21. 30. 00 1988 (vi_Hoa Kỳ);

Di 16 Thg8 21. 30. 00 1988 (de_DE)

(1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7183

Đại diện ngày thích hợp của địa phương

16/08/88 (Không có);

16/08/1988 (en_Mỹ);

16. 08. 1988 (de_DE)

(1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7184

Đại diện thời gian thích hợp của địa phương

21. 30. 00 (vi_US);

21. 30. 00 (de_DE)

(1)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7185

Một ký tự

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7186 theo nghĩa đen

%

Một số chỉ thị bổ sung không bắt buộc theo tiêu chuẩn C89 được bao gồm để thuận tiện. Tất cả các tham số này đều tương ứng với các giá trị ngày theo tiêu chuẩn ISO 8601

Directive

Meaning

Example

Notes

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7187

Năm ISO 8601 với thế kỷ đại diện cho năm chứa phần lớn tuần ISO (

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7188)

0001, 0002, …, 2013, 2014, …, 9998, 9999

(số 8)

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7189

ISO 8601 ngày trong tuần dưới dạng số thập phân trong đó 1 là Thứ Hai

1, 2, …, 7

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7188

ISO 8601 tuần dưới dạng số thập phân với Thứ Hai là ngày đầu tuần. Tuần 01 là tuần có ngày 04/01

01, 02, …, 53

(8), (9)

Những thứ này có thể không khả dụng trên tất cả các nền tảng khi được sử dụng với phương pháp

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7140. Chỉ thị năm và tuần ISO 8601 không thể hoán đổi cho nhau với chỉ thị số năm và tuần ở trên. Gọi _____17141 với các chỉ thị ISO 8601 không đầy đủ hoặc mơ hồ sẽ tăng ____5493

Toàn bộ mã định dạng được hỗ trợ khác nhau giữa các nền tảng, vì Python gọi hàm

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7140 của thư viện C và các biến thể nền tảng là phổ biến. Để xem toàn bộ mã định dạng được hỗ trợ trên nền tảng của bạn, hãy tham khảo tài liệu strftime(3). Cũng có sự khác biệt giữa các nền tảng trong việc xử lý các thông số định dạng không được hỗ trợ

Mới trong phiên bản 3. 6. ______17187,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7189 và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7188 đã được thêm vào.

Chi tiết kỹ thuật¶

Nói chung,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7198 hoạt động giống như mô-đun
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
900 của
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 mặc dù không phải tất cả các đối tượng đều hỗ trợ phương thức
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
242

Đối với phương thức lớp

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7146, giá trị mặc định là
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
903. bất kỳ thành phần nào không được chỉ định trong chuỗi định dạng sẽ được lấy từ giá trị mặc định. 4

Sử dụng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
904 tương đương với

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
21

ngoại trừ khi định dạng bao gồm các thành phần giây phụ hoặc thông tin bù múi giờ, được hỗ trợ trong

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
905 nhưng bị loại bỏ bởi
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
906

Đối với đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0, không nên sử dụng mã định dạng cho năm, tháng và ngày vì đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 không có giá trị như vậy. Nếu chúng vẫn được sử dụng, thì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
909 được thay thế cho năm và
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
35 cho tháng và ngày

Đối với đối tượng

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32, không nên sử dụng mã định dạng cho giờ, phút, giây và micro giây vì đối tượng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 không có các giá trị như vậy. Nếu chúng vẫn được sử dụng, thì
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
414 sẽ được thay thế cho chúng

Vì lý do tương tự, việc xử lý các chuỗi định dạng chứa các điểm mã Unicode không thể được biểu thị trong bộ ký tự của ngôn ngữ hiện tại cũng phụ thuộc vào nền tảng. Trên một số nền tảng, các điểm mã như vậy được giữ nguyên trong đầu ra, trong khi trên các nền tảng khác,

>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7150 có thể tăng
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback (most recent call last):
  File "", line 1, in 
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
915 hoặc thay vào đó trả về một chuỗi trống

ghi chú

  1. Vì định dạng phụ thuộc vào ngôn ngữ hiện tại nên cần cẩn thận khi đưa ra các giả định về giá trị đầu ra. Thứ tự trường sẽ khác nhau (ví dụ: “tháng/ngày/năm” so với “ngày/tháng/năm”) và đầu ra có thể chứa các ký tự Unicode được mã hóa bằng mã hóa mặc định của ngôn ngữ (ví dụ: nếu ngôn ngữ hiện tại là

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    916,

  2. Phương pháp

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141 có thể phân tích các năm trong phạm vi [1, 9999] đầy đủ, nhưng các năm < 1000 phải được điền bằng 0 để có chiều rộng 4 chữ số

    Đã thay đổi trong phiên bản 3. 2. Trong các phiên bản trước, phương pháp

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7140 bị giới hạn trong các năm >= 1900.

    Đã thay đổi trong phiên bản 3. 3. Trong phiên bản 3. 2, phương pháp

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7140 bị giới hạn trong các năm >= 1000.

  3. Khi được sử dụng với phương thức

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141, lệnh
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7172 chỉ ảnh hưởng đến trường giờ đầu ra nếu lệnh
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7171 được sử dụng để phân tích cú pháp giờ

  4. Không giống như mô-đun

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    0, mô-đun
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 không hỗ trợ giây nhuận

  5. Khi được sử dụng với phương thức

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141, chỉ thị
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7175 chấp nhận từ một đến sáu chữ số và số không ở bên phải.
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7175 là một phần mở rộng cho tập hợp các ký tự định dạng trong tiêu chuẩn C (nhưng được triển khai riêng trong các đối tượng ngày giờ và do đó luôn có sẵn)

  6. Đối với một đối tượng ngây thơ, mã định dạng

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7176 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7178 được thay thế bằng các chuỗi rỗng

    Đối với một đối tượng nhận thức

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7176

    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    57 được chuyển đổi thành một chuỗi có dạng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7177, trong đó
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    67 là chuỗi 2 chữ số cho biết số giờ bù giờ UTC,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    938 là chuỗi 2 chữ số cho biết số phút bù giờ UTC,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    939 là chuỗi 2 chữ số cho biết . Phần
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    940 bị bỏ qua khi phần bù là một số nguyên của giây và cả phần
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    940 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    939 đều bị bỏ qua khi phần bù là một số nguyên phút. Ví dụ: nếu
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    57 trả về
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    945, thì
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7176 được thay thế bằng chuỗi
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    947

    Changed in version 3. 7. The UTC offset is not restricted to a whole number of minutes.

    Đã thay đổi trong phiên bản 3. 7. Khi chỉ thị

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7176 được cung cấp cho phương thức
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141, phần bù UTC có thể có dấu hai chấm làm dấu phân cách giữa giờ, phút và giây. Ví dụ:
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    950 sẽ được phân tích thành phần bù của một giờ. Ngoài ra, cung cấp
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    951 giống với
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    952.

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7178

    Trong

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7140,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7178 được thay thế bằng một chuỗi rỗng nếu
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    165 trả về
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    403;

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141 chỉ chấp nhận các giá trị nhất định cho
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7178

    1. bất kỳ giá trị nào trong

      >>> delta2 > delta1
      True
      >>> delta2 > 5
      Traceback (most recent call last):
        File "", line 1, in 
      TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
      
      961 cho ngôn ngữ máy của bạn

    2. các giá trị mã hóa cứng

      >>> delta2 > delta1
      True
      >>> delta2 > 5
      Traceback (most recent call last):
        File "", line 1, in 
      TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
      
      962 và
      >>> delta2 > delta1
      True
      >>> delta2 > 5
      Traceback (most recent call last):
        File "", line 1, in 
      TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
      
      963

    Vì vậy, ai đó sống ở Nhật Bản có thể có giá trị hợp lệ là

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    964,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    962 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    963, nhưng có thể không phải là
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    967. Nó sẽ tăng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    493 cho các giá trị không hợp lệ

    Đã thay đổi trong phiên bản 3. 2. Khi chỉ thị

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7176 được cung cấp cho phương thức
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141, một đối tượng
    >>> from datetime import timedelta
    >>> delta1 = timedelta(seconds=57)
    >>> delta2 = timedelta(hours=25, seconds=2)
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 nhận biết sẽ được tạo ra.
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    4 của kết quả sẽ được đặt thành phiên bản
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    8.

  7. Khi được sử dụng với phương pháp

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7180 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7181 chỉ được sử dụng trong các phép tính khi ngày trong tuần và năm dương lịch (
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7169) được chỉ định

  8. Tương tự như

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7180 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7181,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7188 chỉ được sử dụng trong tính toán khi ngày trong tuần và năm ISO (
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7187) được chỉ định trong chuỗi định dạng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141. Cũng lưu ý rằng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7187 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7169 không thể hoán đổi cho nhau

  9. Khi được sử dụng với phương pháp

    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7141, số 0 đứng đầu là tùy chọn đối với các định dạng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7164,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7167,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7170,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7171,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7173,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7174,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7179,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7180,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7181 và
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7188. Định dạng
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback (most recent call last):
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    7168 không yêu cầu số 0 đứng đầu

chú thích

1

Nghĩa là, nếu chúng ta bỏ qua các tác động của Thuyết tương đối

2

Điều này phù hợp với định nghĩa của lịch “proleptic Gregorian” trong cuốn sách Tính toán Lịch của Dershowitz và Reingold, trong đó nó là lịch cơ sở cho tất cả các phép tính. Xem sách để biết các thuật toán chuyển đổi giữa các thứ tự Gregorian proleptic và nhiều hệ thống lịch khác