Làm thế nào để tôi bắt đầu một tuần từ chủ nhật 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

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. Whether a naive object represents Coordinated Universal Time [UTC], local time, or time in some other timezone is purely up to the program, just like it is up to the program whether a particular number represents metres, miles, or mass. Naive objects are easy to understand and to work with, at the cost of ignoring some aspects of reality

For applications requiring aware objects,

>>> 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 have an optional time zone information attribute,
>>> 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, that can be set to an instance of a subclass of the abstract
>>> 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. These
>>> 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 capture information about the offset from UTC time, the time zone name, and whether daylight saving time is in effect

Only one concrete

>>> 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, 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'
8 class, is supplied by the
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 module. 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'
8 class can represent simple timezones with fixed offsets from UTC, such as UTC itself or North American EST and EDT timezones. Supporting timezones at deeper levels of detail is up to the application. The rules for time adjustment across the world are more political than rational, change frequently, and there is no standard suitable for every application aside from UTC

Constants¶

The

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 module exports the following constants

datetime. MINYEAR

The smallest year number allowed 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'
32 or
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 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'
34 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'
35

datetime. MAXYEAR

The largest year number allowed 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'
32 or
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 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'
38 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'
39

datetime. UTC

Alias for the UTC timezone singleton

>>> 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

Available Types¶

class datetime. date

An idealized naive date, assuming the current Gregorian calendar always was, and always will be, in effect. 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'
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, 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'
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

Xác định xem một đối tượng là Aware hay 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ơ

Sự khác biệt giữa nhận thức và ngây thơ không áp dụng cho 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

>>> 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 Đố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'
411 đại diện cho một khoảng thời gian, sự khác biệt giữa hai ngày hoặc thời gian

lớp ngày giờ. timedelta[ngày=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0]

Tất cả các đối số là tùy chọn và 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'
414. Các đối số có thể là số nguyên hoặc số float và có thể dương hoặc âm

Chỉ ngày, giây và micro giây được lưu trữ nội bộ. Các đối số được chuyển đổi thành các đơn vị đó

  • Một phần nghìn giây được chuyển đổi thành 1000 micro giây

  • Một phút được chuyển thành 60 giây

  • Một giờ được chuyển đổi thành 3600 giây

  • Một tuần được chuyển đổi thành 7 ngày

và ngày, giây và micro giây sau đó được chuẩn hóa để biểu diễn là duy nhất, 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'
    
    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 [số giây trong một 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'
    
    417

Ví dụ sau đây minh họa cách mọi đối số ngoài ngày, giây và micro giây được “hợp nhất” và chuẩn hóa thành ba thuộc tính kết quả đó

>>> 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ếu bất kỳ đối số nào là số float và có micro giây phân số, thì micro giây phân số còn lại từ tất cả các đối số sẽ được kết hợp và tổng của chúng được làm tròn đến micro giây gần nhất bằng cách sử dụng bộ ngắt kết nối nửa vòng đến chẵn. Nếu không có đối số nào là float, quá trình chuyển đổi và chuẩn hóa là chính xác [không có thông tin nào bị mất]

Nếu giá trị chuẩn hóa của ngày nằm ngoài phạm vi được chỉ định, 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'
418 được tăng lên

Lưu ý rằng việc chuẩn hóa các giá trị âm lúc đầu có thể gây ngạc nhiên. 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'
2

Thuộc tính lớp

đồng bằng thời gian. phú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 tiêu cực 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'
420

đồng bằng thời gian. tối đ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 tích cực 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'
422

đồng bằng thời gian. độ phân giải

Sự khác biệt nhỏ nhất có thể giữa 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 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

Lưu ý rằng, do chuẩn hóa, ________ 5425 > ________ 5426.

>>> 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 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

Thuộc tính phiên bản [chỉ đọc]

Thuộc tính

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

Giữa -999999999 và bao gồm cả 999999999

>>> 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

Bao gồm từ 0 đến 86399

>>> 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

Bao gồm từ 0 đến 999999

hoạt động được hỗ trợ

Hoạt động

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

Tổng của t2 và t3. Sau đó t1-t2 == t3 và t1-t3 == t2 là đú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'
433

Sự khác biệt của t2 và t3. Sau đó t1 == t2 - t3 và t2 == t1 + t3 là đúng. [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. Sau đó t1 // i == t2 là đúng, với điều kiệ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'
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 nhân với một số float. Kết quả được làm tròn đến bội số gần nhất của 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

Computes the quotient and the remainder.

>>> 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

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'
411[-t1. days, -t1. seconds, -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

equivalent to +t 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'
453, and to -t 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'
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

Returns a string in the form

>>> 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, where D is negative for 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'
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

Returns a string representation of 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'
411 object as a constructor call with canonical attribute values

Notes

  1. This is exact but may overflow

  2. This is exact and cannot overflow

  3. Division by 0 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'
    
    460

  4. -timedelta. max 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

  5. String representations 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'
    
    411 objects are normalized similarly to their internal representation. This leads to somewhat unusual results for negative timedeltas. 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'
    
    17

  6. The expression

    >>> 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 will always be equal to the expression
    >>> 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 except when t3 is equal 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'
    
    425; in that case the former will produce a result while the latter will overflow

In addition to the operations listed 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'
411 objects support certain additions and subtractions 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'
32 and
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 objects [see below]

Changed in version 3. 2. Floor division and true division 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'
411 object by another
>>> 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 are now supported, as are remainder operations 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'
471 function. True division and multiplication 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'
411 object by 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 are now supported.

Comparisons 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'
411 objects are supported, with some caveats

The comparisons

>>> 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 always 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'
477, no matter the type of the compared object

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

For all other comparisons [such 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'
478 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'
479], 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'
411 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

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

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'
411 object is considered to be true if and only if it isn’t equal 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'
483

Instance methods

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]

Note that for very large time intervals [greater than 270 years on most platforms] this method will lose microsecond accuracy

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

Examples 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'
411 arithmetic

>>> 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 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'
32 object represents a date [year, month and day] in an idealized calendar, the current Gregorian calendar indefinitely extended in both directions

January 1 of year 1 is called day number 1, January 2 of year 1 is called day number 2, and so on. 2

class datetime. date[year , month , day]

All arguments are required. 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'
    
    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

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

Other constructors, all class methods

classmethod date. today[]

Return the current local date

This 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'
494

classmethod date. fromtimestamp[timestamp]

Return the local date corresponding to the POSIX timestamp, such as is returned 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'
495

This may 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'
418, if the timestamp is out of the range of values supported by the platform 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 function, 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'
498 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'
497 failure. It’s common for this to be restricted to years from 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored 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'
200

Changed in version 3. 3. 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'
418 instead 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'
493 if the timestamp is out of the range of values supported by the platform 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 function. 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'
498 instead 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'
493 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'
497 failure.

classmethod date. 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

Thuộc tính lớp

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

Thuộc tính phiên bản [chỉ đọc]

ngày. năm

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'
34 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'
38 inclusive

ngày. month

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

hoạt động được hỗ trợ

Hoạt động

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 is considered less than date2 when date1 precedes date2 in time. [4]

Notes

  1. date2 is moved forward in time 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'
    
    226, or backward 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'
    
    227. Afterward
    >>> 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 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'
    
    230 are ignored.
    >>> 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 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'
    
    232 would be smaller than
    >>> 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 or larger than
    >>> 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 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'
    
    230 are ignored

  3. Điều này là chính xác và không thể tràn. timedelta. seconds and timedelta. microseconds are 0, and date2 + timedelta == date1 after

  4. In other words,

    >>> 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 if and only 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'
    
    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. However,
    >>> 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 is returned instead if the other comparand has 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'
    
    242 attribute. This hook gives other kinds of date objects a chance at implementing mixed-type comparison. If not, 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'
    
    32 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

In Boolean contexts, all

>>> 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 objects are considered to be true

Instance methods

date. replace[year=self. year , month=self. month , day=self. day]

Return a date with the same value, except for those parameters given new values by whichever keyword arguments are specified

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'
9

date. timetuple[]

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'
250 such as returned 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'
251

The hours, minutes and seconds are 0, and the DST flag is -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 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'
40

where

>>> 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 is the day number within the current year starting 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'
35 for January 1st

date. toordinal[]

Return the proleptic Gregorian ordinal of the date, where January 1 of year 1 has ordinal 1. For any

>>> 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 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

date. weekday[]

Return the day of the week as an integer, where Monday is 0 and Sunday is 6. 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'
257, a Wednesday. See also
>>> 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

date. isoweekday[]

Return the day of the week as an integer, where Monday is 1 and Sunday is 7. 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'
259, a Wednesday. See also
>>> 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

date. isocalendar[]

Return a named tuple object with three components.

>>> 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 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'
264.

The ISO calendar is a widely used variant of the Gregorian calendar. 3

The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first [Gregorian] calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year

For example, 2004 begins on a Thursday, so the first week of ISO year 2004 begins on Monday, 29 Dec 2003 and ends on Sunday, 4 Jan 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

Changed in version 3. 9. Result changed from a tuple to a named tuple .

date. isoformat[]

Return a string representing the date 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'
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

date. __str__[]

For a date 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'
267

date. ctime[]

Return a string representing the date

>>> 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 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'
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'
271 does not invoke] conforms to the C standard

date. strftime[format]

Return a string representing the date, controlled by an explicit format string. Format codes referring to hours, minutes or seconds will see 0 values. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .

date. __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'
272. 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'
32 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.
>>> 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¶

Example of counting days to an event

>>> 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

More examples of working 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'
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 Objects¶

A

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object is a single object containing all the information from 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'
32 object 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

Like 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'
32 object,
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 assumes the current Gregorian calendar extended in both directions; like 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,
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 assumes there are exactly 3600*24 seconds in every day

Constructor

class datetime. datetime[year , month , day , hour=0 , minute=0 , second=0 , microsecond=0 , tzinfo=None , * , fold=0]

The year, month and day arguments are required. 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'
    
    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

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

New in version 3. 6. Added 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'
296 argument.

Other constructors, all class methods

classmethod datetime. today[]

Return the current local datetime, 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
>>> 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

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'
47

See also

>>> 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

This method is functionally 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'
299, but without 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'
1702 parameter

classmethod datetime. now[tz=None]

Return the current local date and time

If optional argument tz 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 or not specified, this is 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'
1704, but, if possible, supplies more precision than can be gotten from going through 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'
495 timestamp [for example, this may be possible on platforms supplying the 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 function]

If tz is not

>>> 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, it 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 the current date and time are converted to tz’s time zone

This function is preferred over

>>> 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 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'
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

This is 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'
299, but returns the current UTC date and time, as a naive
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 object. An aware current UTC datetime can be obtained by calling
>>> 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. See also
>>> 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

Warning

Because naive

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 objects are treated by many
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 methods as local times, it is preferred to use aware datetimes to represent times in UTC. As such, the recommended way to create an object representing the current time in UTC is by calling
>>> 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

classmethod datetime. fromtimestamp[timestamp , tz=None]

Return the local date and time corresponding to the POSIX timestamp, such as is returned 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'
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ơ

If tz is not

>>> 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, it 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 the timestamp is converted to tz’s time zone

>>> 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 may 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'
418, if the timestamp is out of the range of values supported by the platform 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 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'
1728 functions, 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'
498 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'
497 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'
1728 failure. It’s common for this to be restricted to years in 1970 through 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
>>> 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 C. 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

Để nhận biết 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, hãy 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'
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

Warning

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 được nâng lên nếu chuỗi ngày và định dạng không thể được phân tích cú pháp 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'
1787 hoặc nếu nó trả về một giá trị không phải là bộ thời gian. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime[] và strptime[] Hành vi .

Thuộc tính lớp

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

Thuộc tính phiên bản [chỉ đọc]

ngày giờ. năm

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'
34 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'
38 inclusive

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

datetime. 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

datetime. microsecond

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'
1799

datetime. tzinfo

The object passed as the tzinfo argument to the

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 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

datetime. fold

In

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
02. Used to disambiguate wall times during a repeated interval. [A repeated interval occurs when clocks are rolled back at the end of daylight saving time or when the UTC offset for the current zone is decreased for political reasons. ] The value 0 [1] represents the earlier [later] of the two moments with the same wall time representation

New in version 3. 6

hoạt động được hỗ trợ

Hoạt động

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

Compares

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 to
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7. [4]

  1. datetime2 is a duration of timedelta removed from datetime1, moving forward in time 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'
    
    221 > 0, or backward 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'
    
    221 < 0. The result has 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 as the input datetime, and datetime2 - datetime1 == timedelta after.
    >>> 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 if datetime2. year would be smaller than
    >>> 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 or larger than
    >>> 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. Note that no time zone adjustments are done even if the input is an aware object

  2. Computes the datetime2 such that datetime2 + timedelta == datetime1. As for addition, the result has 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 as the input datetime, and no time zone adjustments are done even if the input is aware

  3. Subtraction of a

    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 from a
    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 is defined only if both operands are naive, or if both are aware. If one is aware and the other is 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'
    
    481 is raised

    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. No time zone adjustments are done in this case

    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. The result is
    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    25 except that the implementation never overflows

  4. datetime1 is considered less than datetime2 when datetime1 precedes datetime2 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 datetimes are compared. 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]

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

    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 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.

    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. However,
    >>> 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 is returned instead if the other comparand has 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'
    
    242 attribute. This hook gives other kinds of date objects a chance at implementing mixed-type comparison. If not, 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 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

Instance methods

datetime. ngày[]

Trả 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 có cùng năm, tháng và ngày

datetime. thời gian[]

Trả 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 có cùng giờ, phút, giây, micro giây và 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'
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. Xem thêm phương pháp
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
47

Đã thay đổi trong phiên bản 3. 6. Giá trị của màn hình đầu tiên được sao chép vào đố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 được trả về.

ngày giờ. timetz[]

Trả 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 có cùng thuộc tính giờ, phút, giây, micro giây, nếp gấp và tzinfo. Xem thêm phương pháp
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
50

Đã thay đổi trong phiên bản 3. 6. Giá trị của màn hình đầu tiên được sao chép vào đố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 được trả về.

ngày giờ. thay thế[năm=chính mình. năm , tháng=mình. tháng , ngày=chính mình. ngày , giờ=chính mình. giờ , phút=chính mình. phút , giây=chính mình. giây , micro giây=chính mình. micro giây , tzinfo=self. tzinfo , * , gấp=0]

Trả về một ngày giờ có cùng thuộc tính, ngoại trừ những thuộc tính được cung cấp giá trị mới theo bất kỳ đối số từ khóa nào được chỉ định. Lưu ý rằng có thể chỉ định

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
52 để tạo một ngày giờ ngây thơ từ một ngày giờ nhận thức mà không cần chuyển đổi dữ liệu ngày và giờ

New in version 3. 6. Added 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'
296 argument.

ngày giờ. múi giờ[tz=Không có]

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 với 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 mới tz, điều chỉnh dữ liệu ngày và giờ để kết quả có cùng thời gian UTC với chính nó, nhưng theo giờ địa phương của tz

Nếu được cung cấp, tz 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à các phương thức
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 và
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 của nó không được 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. Nếu bản thân là ngây thơ, nó được coi là đại diện cho thời gian trong múi giờ hệ thống

Nếu được gọi mà không có đối số [hoặc với

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
60], múi giờ cục bộ của hệ thống được giả định cho múi giờ đích. Thuộc tính
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
61 của phiên bản datetime đã chuyển đổi sẽ được đặt thành phiên bản 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'
8 với tên vùng và phần bù thu được từ HĐH

Nếu

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
63 là tz, thì
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
64 là chính mình. không thực hiện điều chỉnh dữ liệu ngày hoặc giờ. Mặt khác, kết quả là giờ địa phương trong múi giờ tz, biểu thị cùng thời gian UTC với chính mình. sau ________ 065, ________ 066 sẽ có dữ liệu ngày giờ giống như
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
67

Nếu bạn chỉ muốn đính kèm một đối tượng múi giờ tz vào một datetime dt mà không cần điều chỉnh dữ liệu ngày và giờ, hãy sử dụng

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
68. Nếu bạn chỉ muốn xóa đối tượng múi giờ khỏi dt datetime nhận biết mà không chuyển đổi dữ liệu ngày và giờ, hãy sử dụng
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
69

Lưu ý rằng phương thức

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
70 mặc định có thể được ghi đè trong 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 để ảnh hưởng đến kết quả được trả về bởi
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
72. Bỏ qua các trường hợp lỗi,
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 hoạt độ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'
22

Đã thay đổi trong phiên bản 3. 3. tz bây giờ có thể được bỏ qua.

Đã thay đổi trong phiên bản 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.

ngày giờ. utcoffset[]

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
78 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. Phần bù UTC không bị giới hạn trong một số nguyên của phút.

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[]

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'
250 such as returned 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'
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 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'
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

Warning

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

ngày giờ. 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ờ. 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. 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']

Trả về một chuỗi biểu thị ngày và giờ ở đị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'
    
    49, 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'
    
    17 không phải là 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, 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'
    
    17 là 0

Nếu

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 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, một chuỗi sẽ được thêm vào, tạo ra phần bù 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'
    
    55, 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'
    
    17 không phải là 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, 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'
    
    17 là 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

Đối số tùy chọn sep [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'
59] là dấu tách một ký tự, được đặt giữa phần ngày và giờ của kết quả. 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'
28

Đối số tùy chọn timespec chỉ định số lượng thành phần bổ sung của thời gian cần đưa vào [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'
60]. Nó có thể là một trong những điều sau đâ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'
    
    60. 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'
    
    62 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'
    
    17 là 0, 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'
    
    64 nếu khô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'
    
    65. Bao gồ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'
    
    14 ở định dạng hai chữ 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'
    
    67

  • >>> 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. Bao gồ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'
    
    14 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'
    
    15 ở đị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'
    
    71

  • >>> 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. Bao gồ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'
    
    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 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'
    
    16 ở đị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'
    
    76

  • >>> 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. Bao gồm toàn thời gian, nhưng cắt ngắn phần thứ hai thành mili giây. Đị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'
    
    78

  • >>> 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. Bao gồm toàn thời gian ở đị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'
    
    80

Ghi chú

Các thành phần thời gian bị loại trừ bị cắt bớt, không được làm trò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'
493 sẽ được nâng lên trên một đối số timespec không hợp 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'
29

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

ngày giờ. __str__[]

Đối với 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 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'
84

ngày giờ. thời gian[]

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

>>> 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

Chuỗi đầu ra sẽ không bao gồm thông tin múi giờ, bất kể đầu vào là nhận biết hay 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'
268 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'
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
>>> 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 không gọi] tuân theo tiêu chuẩn C

ngày giờ. thời gian strf[định dạng]

Trả về một chuỗi đại diện cho ngày và giờ, được kiểm soát bởi một chuỗi định dạng rõ ràng. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime[] và strptime[] Hành vi .

ngày giờ. __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'
89. Điều này cho phép chỉ định một chuỗi định dạng cho 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 trong các chuỗi ký tự đượ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.
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False

Ví dụ làm việc với đối tượng

>>> 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'
172

Ví dụ bên dưới định nghĩa một 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 thu thập thông tin múi giờ cho Kabul, Afghanistan, sử dụng +4 UTC cho đến năm 1945 và sau đó là +4. 30 UTC 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'
173

Cách sử dụng 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'
95 từ phía trê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'
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¶

Đố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 đại diện cho thời gian trong ngày [cục bộ], không phụ thuộc vào bất kỳ ngày cụ thể nào và có thể điều chỉnh thông qua đố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

lớp ngày giờ. thời gian[giờ=0, minute=0, second=0, microsecond=0, tzinfo=None, *, fold=0]

Tất cả các đối số là tùy chọn. tzinfo có thể 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 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. 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'
    
    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. Tất cả 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'
414 ngoại trừ tzinfo, 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'
403

Thuộc tính lớp

thời gian. phút

Đạ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'
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

thời gian. tối đa

Đạ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'
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

thời gian. độ phân giải

Sự khác biệt nhỏ nhất có thể giữa 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'
0 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, mặc dù lưu ý rằng số học 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'
0 không được hỗ trợ

Thuộc tính phiên bản [chỉ đọc]

thời gian. 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

thời gian. 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

thời gian. 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

thời gian. micro giây

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'
1799

thời gian. tzinfo

Đối tượng được truyền dưới dạng đối số tzinfo cho hàm tạ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'
0 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

thời gian. gấp

In

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
02. Used to disambiguate wall times during a repeated interval. [A repeated interval occurs when clocks are rolled back at the end of daylight saving time or when the UTC offset for the current zone is decreased for political reasons. ] The value 0 [1] represents the earlier [later] of the two moments with the same wall time representation

New in version 3. 6

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'
0 hỗ trợ so sánh 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'
0 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'
0, trong đó a được coi là nhỏ hơn b khi a đứng trước b 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, thì 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 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]. Để ngăn các so sánh kiểu hỗn hợp quay trở lại so sánh mặc định theo địa chỉ đối tượ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'
0 đượ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 phép 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

Đã thay đổi trong phiên bản 3. 3. So sánh bình đẳng giữa các trường hợ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'
0 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.

Trong ngữ cảnh Boolean, đố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 luôn được coi là đúng

Đã thay đổi trong phiên bản 3. 5. Trước Python 3. 5, 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 được coi là sai nếu nó đại diện cho nửa đêm theo giờ UTC. Hành vi này được coi là tối nghĩa và dễ bị lỗi và đã bị xóa trong Python 3. 5. Xem bpo-13936 để biết chi tiết đầy đủ.

nhà xây dựng khác

phương pháp phân lớp thời gian. fromisoformat[time_string]

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'
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. >>> 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 hàng đầu, thường được yêu cầu trong trường hợp có thể có sự mơ hồ giữa ngày và giờ, không bắt buộc

  3. Phân số giây có thể có bất kỳ số lượng chữ số nào [bất kỳ số nào vượt quá 6 sẽ bị cắt ngắn]

  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

Đã 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'
343.

Instance methods

thời gian. thay thế[giờ=chính mình. giờ , phút=chính mình. phút , giây=chính mình. giây , micro giây=chính mình. micro giây , tzinfo=self. tzinfo , * , gấp=0]

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 có cùng giá trị, ngoại trừ những thuộc tính được cung cấp giá trị mới theo bất kỳ đối số từ khóa nào được chỉ định. Lưu ý rằng có thể chỉ định
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
52 để tạo 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 ngây thơ từ 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 nhận thức mà không cần chuyển đổi dữ liệu thời gian

New in version 3. 6. Added 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'
296 argument.

time. isoformat[timespec=']

Trả về một chuỗi biểu thị thời gian ở định dạng ISO 8601, mộ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'
    
    80, 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'
    
    17 không phải là 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, 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'
    
    17 là 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, nếu
    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    57 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

  • >>> 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, 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'
    
    17 là 0 và
    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    57 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

Đối số tùy chọn timespec chỉ định số lượng thành phần bổ sung của thời gian cần đưa vào [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'
60]. Nó có thể là một trong những điều sau đâ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'
    
    60. 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'
    
    62 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'
    
    17 là 0, 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'
    
    64 nếu khô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'
    
    65. Bao gồ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'
    
    14 ở định dạng hai chữ 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'
    
    67

  • >>> 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. Bao gồ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'
    
    14 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'
    
    15 ở đị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'
    
    71

  • >>> 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. Bao gồ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'
    
    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 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'
    
    16 ở đị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'
    
    76

  • >>> 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. Bao gồm toàn thời gian, nhưng cắt ngắn phần thứ hai thành mili giây. Đị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'
    
    78

  • >>> 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. Bao gồm toàn thời gian ở đị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'
    
    80

Ghi chú

Các thành phần thời gian bị loại trừ bị cắt bớt, không được làm trò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'
493 sẽ được nâng lên trên một đối số timespec không hợp lệ

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'
176

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

thời gian. __str__[]

Trong thời gian 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 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'
383

thời gian. thời gian strf[định dạng]

Trả về một chuỗi biểu thị thời gian, được kiểm soát bởi một chuỗi định dạng rõ ràng. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime[] và strptime[] Hành vi .

thời gian. __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'
384. Điều này cho phép chỉ định một chuỗi định dạng 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'
0 trong các chuỗi ký tự đượ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 .

thời gian. utcoffset[]

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ề
>>> 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 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. Phần bù UTC không bị giới hạn trong một số nguyên của phút.

thời gian. 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ề
>>> 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 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.

thời gian. 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, nếu không thì 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'
102 hoặc đư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

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'

Ví dụ về làm việc 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

>>> 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 Đối tượng¶

lớp ngày giờ. tzinfo

Đây là một lớp cơ sở trừu tượng, có nghĩa là lớp này không được khởi tạo trực tiếp. Xác định 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 để nắm bắt thông tin về một múi giờ cụ thể

Một thể hiện của [một lớp con cụ thể 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 có thể được truyền cho các hàm tạo đối vớ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 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ác đối tượng thứ hai xem các thuộc tính của chúng là theo giờ địa phương 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'
4 hỗ trợ các phương thức tiết lộ phần bù giờ địa phương từ UTC, tên của múi giờ và phần bù DST, tất cả đều liên quan đến đối tượng ngày hoặc giờ được truyền cho chúng

Bạn cần lấy được một phân lớp cụ thể và [ít nhất] cung cấp các triển khai của các 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 tiêu chuẩn cần thiết cho các 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 mà bạn sử dụng. Mô-đun
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 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'
8, một phân lớp cụ thể đơn giản 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 có thể biểu thị các múi giờ có phần bù cố định từ UTC, chẳng hạn như chính UTC hoặc EST và EDT của Bắc Mỹ

Yêu cầu đặc biệt đối với dưa chua. Một 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 phải có 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'
118 có thể được gọi mà không có đối số, nếu không, nó có thể được chọn nhưng có thể không được giải nén lại. Đây là yêu cầu kỹ thuật có thể được nới lỏng trong tương lai

Một phân lớp cụ thể 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 có thể cần triển khai các phương pháp sau. Chính xác những phương pháp nào là cần thiết phụ thuộc vào việc sử dụng 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 nhận thức. Nếu nghi ngờ, chỉ cần thực hiện tất cả chúng

tzinfo. utcoffset[dt]

Trả về phần bù của giờ địa phương từ UTC, 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 dương ở phía đông của UTC. Nếu giờ địa phương ở phía tây của UTC, điều này sẽ là âm

Điều này thể hiện tổng phần bù từ UTC; . Nếu không biết phần bù UTC, hãy 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. Mặt khác, giá trị được trả về phải 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 nằm trong khoảng 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'
126 đế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'
127 [độ lớn của phần bù phải nhỏ hơn một ngày]. Hầu hết các triển khai của
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 có thể sẽ giống như một trong hai

>>> 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

Nếu

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 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, thì
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 cũng không nên 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

Việc thực hiện 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
57 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'
134

Đã thay đổi trong phiên bản 3. 7. Phần bù UTC không bị giới hạn trong một số nguyên của phút.

tzinfo. dst[dt]

Trả về điều chỉnh thời gian tiết kiệm ánh sáng ban ngày [DST], 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 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 biết thông tin DST

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'
483 nếu DST không có hiệu lực. Nếu DST có hiệu lực, hãy trả lại phần bù 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 [xem
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 để biết chi tiết]. Lưu ý rằng phần bù DST, nếu có, đã được thêm vào phần bù UTC do
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
57 trả về, do đó, không cần tham khảo
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 trừ khi bạn muốn nhận thông tin DST riêng. 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'
25 gọi phương thức
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 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'
4 để xác định cách đặt cờ
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
97 và
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
70 gọi
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 để giải thích cho các thay đổi DST khi vượt qua các múi giờ

Ví dụ tz 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 mô hình hóa cả thời gian tiêu chuẩn và thời gian ban ngày phải nhất quán theo nghĩa nà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'
149

phải trả về cùng một kết quả cho mỗi

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 dt 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'
151 Đối với 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 lành mạnh, biểu thức này mang lại "độ lệch chuẩn" của múi giờ, không phụ thuộc vào ngày hoặc giờ mà chỉ phụ thuộc vào vị trí địa lý. 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'
153 dựa vào điều này, nhưng không thể phát hiện vi phạm; . Nếu 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 không thể đảm bảo điều này, nó có thể ghi đè cài đặt 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
70 để hoạt động chính xác với
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 bất kể

Hầu hết các triển khai của

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
58 có thể sẽ giống như một trong hai

>>> 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

hoặc

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

Việc thực hiện 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
58 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'
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]

Trả về tên múi giờ tương ứng với đối tượng

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 dt, dưới dạng chuỗi. Không có gì về tên chuỗi được xác định 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 và không có yêu cầu rằng nó có ý nghĩa cụ thể. Ví dụ: “GMT”, “UTC”, “-500”, “-5. 00”, “EDT”, “US/Eastern”, “America/New York” đều là những câu trả lời hợp lệ. 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 biết tên chuỗi. Lưu ý rằng đây chủ yếu là một phương thức chứ không phải là một chuỗi cố định vì một số 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 sẽ muốn trả về các tên khác nhau tùy thuộc vào giá trị cụ thể của dt được truyền, đặc biệt nếu 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 chiếm thời gian ban ngày

Việc thực hiện mặc định 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'
165 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'
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. Đối tượng
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 chuyển chính nó làm đối số 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 chuyể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'
403 làm đối số. Do đó, các phương thức 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 nên được chuẩn bị để chấp nhận đối số dt 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'
403 hoặc của lớp
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7

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'
403 được thông qua, người thiết kế lớp sẽ quyết định phản hồi tốt nhất. Ví dụ: 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 là phù hợp nếu lớp muốn nói rằng các đối tượng thời gian không tham gia vào các giao 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. 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

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 truyền để phản hồi một 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, 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'
181 chính là đối tượng như self. Các 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 có thể dựa vào điều này, trừ khi mã người dùng gọi trực tiếp các 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ục đích là các 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 diễn giải dt theo giờ địa phương và không cần lo lắng về các đối tượng ở các múi giờ khác

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

Most

>>> 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 should be able to inherit the 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'
188 implementation without problems. It’s strong enough to handle fixed-offset time zones, and time zones accounting for both standard and daylight time, and the latter even if the DST transition times differ in different years. 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ị. The default implementations of
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 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'
188 may not produce the result you want if the result is one of the hours straddling the moment the standard offset changes

Skipping code for error cases, the 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'
188 implementation acts like

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

In 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'
195 file there are some examples 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 classes

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

Note that there are unavoidable subtleties twice per year 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 accounting for both standard and daylight time, at the DST transition points. For concreteness, consider US Eastern [UTC -0500], where EDT begins the minute after 1. 59 [EST] on the second Sunday in March, and ends the minute after 1. 59 [EDT] on the first Sunday in November

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

When DST starts [the “start” line], the local wall clock leaps from 1. 59 to 3. 00. A wall time of the form 2. MM doesn’t really make sense on that day, so

>>> 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 won’t deliver a result 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'
199 on the day DST begins. For example, at the Spring forward transition of 2016, we get

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

When DST ends [the “end” line], there’s a potentially worse problem. there’s an hour that can’t be spelled unambiguously in local wall time. the last hour of daylight time. In Eastern, that’s times of the form 5. MM UTC on the day daylight time ends. The local wall clock leaps from 1. 59 [thời gian ban ngày] trở lại 1. 00 [standard time] again. Giờ địa phương của mẫu 1. MM are ambiguous.

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
72 mimics the local clock’s behavior by mapping two adjacent UTC hours into the same local hour then. In the Eastern example, UTC times of the form 5. MM and 6. MM both map to 1. MM when converted to Eastern, but earlier times have 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'
296 attribute set to 0 and the later times have it set to 1. For example, at the Fall back transition of 2016, we get

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

Note that the

>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 instances that differ only by the value of 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'
296 attribute are considered equal in comparisons

Applications that can’t bear wall-time ambiguities should explicitly check the value of 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'
296 attribute or avoid using hybrid
>>> 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; there are no ambiguities 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'
8, or any other fixed-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'
4 subclass [such as a class representing only EST [fixed offset -5 hours], or only EDT [fixed offset -4 hours]]

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ù trừ 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 brings the IANA timezone database [also known as the Olson database] to Python, and its usage is recommended

IANA timezone database

The Time Zone Database [often called tz, tzdata or zoneinfo] contains code and data that represent the history of local time for many representative locations around the globe. 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

Objects of this class cannot be used to represent timezone information in the locations where different offsets are used in different days of the year or where historical changes have been made to civil time

class datetime. timezone[offset , name=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. It must be 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, 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'
493 is raised

The name argument is optional. If specified it must be a string that will be used as the value returned by 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'
7120 method

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

Đã thay đổi trong phiên bản 3. 7. Phần bù UTC không bị giới hạn trong một số nguyên của phút.

timezone. utcoffset[dt]

Return the fixed value specified when 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'
8 instance is constructed

Đối số dt bị bỏ qua. The return value 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 instance equal to the difference between the local time and UTC

Đã thay đổi trong phiên bản 3. 7. Phần bù UTC không bị giới hạn trong một số nguyên của phút.

múi giờ. tzname[dt]

Return the fixed value specified when 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'
8 instance is constructed

If name is not provided in the constructor, the name returned 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'
7124 is generated from the value of 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'
7125 as follows. If offset 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'
483, the name is “UTC”, otherwise it is a string in the 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'
7127, where ± is the sign 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'
7125, HH and MM are two digits 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'
7129 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'
7130 respectively

Changed in version 3. 6. Name generated from

>>> 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 is now plain
>>> 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, not
>>> 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.

timezone. 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

Thuộc tính lớp

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

Ngày trong tuần là tên đầy đủ của ngôn ngữ

Sunday, Monday, …, Saturday [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

Weekday as a decimal number, where 0 is Sunday and 6 is Saturday

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

Day of the month as a zero-padded decimal number

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

Month as locale’s abbreviated name

Jan, Feb, …, Dec [en_US];

Jan, Feb, …, 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

Month as locale’s full name

January, February, …, December [en_US];

Januar, Februar, …, Dezember [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

Month as a zero-padded decimal number

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

Year without century as a zero-padded decimal number

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

Year with century as a decimal number

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

Hour [24-hour clock] as a zero-padded decimal number

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

Hour [12-hour clock] as a zero-padded decimal number

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

Locale’s equivalent of either AM or PM

AM, PM [en_US];

am, pm [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

Minute as a zero-padded decimal number

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

Second as a zero-padded decimal number

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

Microsecond as a decimal number, zero-padded to 6 digits

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

UTC offset in the form

>>> 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 [empty string if the object is naive]

[empty], +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ơ]

[empty], 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

Day of the year as a zero-padded decimal number

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

Week number of the year [Sunday as the first day of the week] as a zero-padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 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

Week number of the year [Monday as the first day of the week] as a zero-padded decimal number. All days in a new year preceding the first Monday are considered to be in week 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

Locale’s appropriate date and time representation

Tue Aug 16 21. 30. 00 1988 [en_US];

Di 16 Aug 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

Locale’s appropriate date representation

08/16/88 [None];

08/16/1988 [en_US];

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

Locale’s appropriate time representation

21. 30. 00 [en_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

A literal

>>> 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 character

%

Several additional directives not required by the C89 standard are included for convenience. These parameters all correspond to ISO 8601 date values

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

ISO 8601 year with century representing the year that contains the greater part of the ISO week [

>>> 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

[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 weekday as a decimal number where 1 is Monday

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 week as a decimal number with Monday as the first day of the week. Tuần 01 là tuần có ngày 04/01

01, 02, …, 53

[8], [9]

These may not be available on all platforms when used with 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'
7140 method. The ISO 8601 year and ISO 8601 week directives are not interchangeable with the year and week number directives above. Calling
>>> 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 with incomplete or ambiguous ISO 8601 directives will raise 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'
493

The full set of format codes supported varies across platforms, because Python calls the platform C library’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'
7140 function, and platform variations are common. To see the full set of format codes supported on your platform, consult the strftime[3] documentation. There are also differences between platforms in handling of unsupported format specifiers

New in version 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'
7187,
>>> 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 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'
7188 were added.

Technical Detail¶

Broadly speaking,

>>> 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 acts like 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 module’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'
900 although not all objects 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'
242 method

For 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, the default value 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'
903. any components not specified in the format string will be pulled from the default value. 4

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'
904 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'
21

except when the format includes sub-second components or timezone offset information, which are supported 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'
905 but are discarded 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'
906

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'
0 objects, the format codes for year, month, and day should not be used, 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'
0 objects have no such values. If they’re used anyway,
>>> 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 is substituted for the year, 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'
35 for the month and day

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'
32 objects, the format codes for hours, minutes, seconds, and microseconds should not be used, 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'
32 objects have no such values. If they’re used anyway,
>>> 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 is substituted for them

For the same reason, handling of format strings containing Unicode code points that can’t be represented in the charset of the current locale is also platform-dependent. On some platforms such code points are preserved intact in the output, while on others

>>> 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 may 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'
915 or return an empty string instead

Notes

  1. Because the format depends on the current locale, care should be taken when making assumptions about the output value. Field orderings will vary [for example, “month/day/year” versus “day/month/year”], and the output may contain Unicode characters encoded using the locale’s default encoding [for example, if the current locale 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'
    
    916, the default encoding could be any 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'
    
    917,
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback [most recent call last]:
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    918, 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'
    
    919; use
    >>> delta2 > delta1
    True
    >>> delta2 > 5
    Traceback [most recent call last]:
      File "", line 1, in 
    TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
    
    920 to determine the current locale’s encoding]

  2. 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'
    
    7141 method can parse years in the full [1, 9999] range, but years < 1000 must be zero-filled to 4-digit width

    Changed in version 3. 2. In previous versions,

    >>> 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 method was restricted to years >= 1900.

    Changed in version 3. 3. In version 3. 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'
    
    7140 method was restricted to years >= 1000.

  3. When used with 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'
    
    7141 method, 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'
    
    7172 directive only affects the output hour field 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'
    
    7171 directive is used to parse the hour

  4. Unlike 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 module, the
    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 module does not support leap seconds

  5. When used with 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'
    
    7141 method, 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'
    
    7175 directive accepts from one to six digits and zero pads on the right.
    >>> 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 is an extension to the set of format characters in the C standard [but implemented separately in datetime objects, and therefore always available]

  6. For a naive object, 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'
    
    7176 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'
    
    7178 format codes are replaced by empty strings

    For an aware 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'
    
    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 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. For example, if
    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    57 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'
    
    945,
    >>> 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 is replaced with the string
    >>> 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

    Đã thay đổi trong phiên bản 3. 7. Phần bù UTC không bị giới hạn trong một số nguyên của phút.

    Changed in version 3. 7. When 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'
    
    7176 directive is provided 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'
    
    7141 method, the UTC offsets can have a colon as a separator between hours, minutes and seconds. 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'
    
    950 will be parsed as an offset of one hour. In addition, providing
    >>> 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 is identical 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'
    
    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 only accepts certain values 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'
    
    7178

    1. any value 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'
      
      961 for your machine’s locale

    2. the hard-coded values

      >>> 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 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'
      
      963

    So someone living in Japan may have

    >>> 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, 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'
    
    963 as valid values, but probably not
    >>> 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. It will 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'
    
    493 for invalid values

    Changed in version 3. 2. When 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'
    
    7176 directive is provided 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'
    
    7141 method, an aware
    >>> from datetime import timedelta
    >>> delta1 = timedelta[seconds=57]
    >>> delta2 = timedelta[hours=25, seconds=2]
    >>> delta2 != delta1
    True
    >>> delta2 == 5
    False
    
    7 object will be produced. 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 of the result will be set to 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'
    
    8 instance.

  7. When used with 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'
    
    7141 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'
    
    7180 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'
    
    7181 are only used in calculations when the day of the week and the calendar year [
    >>> 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] are specified

  8. Similar 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'
    
    7180 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'
    
    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 is only used in calculations when the day of the week and the ISO year [
    >>> 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] are specified 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'
    
    7141 format string. Also note that
    >>> 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 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'
    
    7169 are not interchangeable

  9. When used with 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'
    
    7141 method, the leading zero is optional for formats
    >>> 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'
    
    992,
    >>> 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, 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'
    
    7188. 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'
    
    7168 does require a leading zero

Footnotes

1

If, that is, we ignore the effects of Relativity

2

This matches the definition of the “proleptic Gregorian” calendar in Dershowitz and Reingold’s book Calendrical Calculations, where it’s the base calendar for all computations. See the book for algorithms for converting between proleptic Gregorian ordinals and many other calendar systems

Chủ Đề