Python lấy ngày hiện tại không có thời gian

Ngày tháng trong Python không phải là kiểu dữ liệu của riêng nó, nhưng chúng ta có thể nhập một mô-đun có tên >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 95 để làm việc với ngày tháng dưới dạng đối tượng ngày tháng

Thí dụ

Nhập mô-đun datetime và hiển thị ngày hiện tại

nhập ngày giờ

x = ngày giờ. ngày giờ. bây giờ()
in(x)

Tự mình thử »

Xuất ngày

Khi chúng tôi thực thi mã từ ví dụ trên, kết quả sẽ là

Ngày chứa năm, tháng, ngày, giờ, phút, giây và micro giây

Mô-đun >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 95 có nhiều phương thức để trả về thông tin về đối tượng ngày tháng

Dưới đây là một vài ví dụ, bạn sẽ tìm hiểu thêm về chúng ở phần sau của chương này

Thí dụ

Trả về năm và tên của ngày trong tuần

nhập ngày giờ

x = ngày giờ. ngày giờ. bây giờ()

in(x. year)
print(x. strftime("%A"))

Tự mình thử »

Creating Date Objects

To create a date, we can use the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 97 class (constructor) of the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 95 module

The >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 97 class requires three parameters to create a date. year, month, day

Thí dụ

Create a date object

nhập ngày giờ

x = datetime. datetime(2020, 5, 17)

print(x)

Tự mình thử »

The >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 97 class also takes parameters for time and timezone (hour, minute, second, microsecond, tzone), but they are optional, and has a default value of >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 001, (>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 002 for timezone)

The strftime() Method

The >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 95 object has a method for formatting date objects into readable strings

The method is called >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 004, and takes one parameter, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 950, to specify the format of the returned string

While date and time arithmetic is supported, the focus of the implementation is on efficient attribute extraction for output formatting and manipulation

See also

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

General calendar related functions

Mô-đun >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 thức" hoặc "ngây thơ" tùy thuộc vào việc chúng có bao gồm thông tin múi giờ hay không

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

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

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

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

Hằng số¶

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

ngày giờ. MINYEAR

Số năm nhỏ nhất được phép trong một đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32 hoặc >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 34 là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 35

ngày giờ. MAX NĂM

Số năm lớn nhất được phép trong một đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32 hoặc >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 38 là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 39

ngày giờ. UTC

Bí danh cho múi giờ UTC đơn lẻ >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 10

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

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

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

Một ngày ngây thơ được lý tưởng hóa, giả sử rằng lịch Gregorian hiện tại luôn có hiệu lực. Thuộc tính. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 11, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 12 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 14, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 15, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 16, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 17 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 11, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 12, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 13, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 14, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 15, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 16, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 17 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403

  2. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403

  2. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411

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

Một đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 415

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 từ 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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

Kết quả

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 434

Delta nhân với một số nguyên. Sau đó t1 // i == t2 là đúng, với điều kiện là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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. độ phân giải sử dụng nửa vòng đến chẵn

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

Chia (3) tổng thời lượng t2 cho đơn vị khoảng thời gian t3. Trả về một đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 438

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

Delta chia cho float hoặc int. Kết quả được làm tròn đến bội số gần nhất của timedelta. độ phân giải sử dụng nửa vòng đến chẵn

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

Sàn được tính và phần còn lại (nếu có) bị vứt đi. Trong trường hợp thứ hai, một số nguyên được trả về. (3)

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

Phần còn lại được tính như một đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411. (3)

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

Tính thương và số dư. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 445 (3) và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 446. q là một số nguyên và r là một đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411

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

Trả về một đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411 có cùng giá trị. (2)

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

tương đương với >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411(-t1. ngày, -t1. giây, -t1. micro giây) và đến t1* -1. (1)(4)

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

tương đương với +t khi >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 453 và -t khi >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 454. (2)

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

Trả về một chuỗi ở dạng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 456, trong đó D là số âm cho số âm của >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 457. (5)

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

Trả về một biểu diễn chuỗi của đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411 dưới dạng lệnh gọi hàm tạo với các giá trị thuộc tính chính tắc

Notes

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

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

  3. Chia cho 0 tăng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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

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

Changed in version 3. 2. Floor division and true division of a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 475 or >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 478 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 479), when a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 481 is raised

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 3

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

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

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

A >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 490

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

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 497 function, and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 498 on >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 418 instead of >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 497 function. Raise >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 498 instead of >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 493 on >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 497 failure.

classmethod date. fromordinal(ordinal)

Return the date corresponding to the proleptic Gregorian ordinal, where January 1 of year 1 has ordinal 1

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 493 is raised unless >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 208. For any date d, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 209

classmethod date. fromisoformat(date_string)

Return a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32 corresponding to a date_string given in any valid ISO 8601 format, except ordinal dates (e. g. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 211)

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

New in version 3. 7

Changed in version 3. 11. Previously, this method only supported the format >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 212.

classmethod date. fromisocalendar(year , week , day)

Return a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32 corresponding to the ISO calendar date specified by year, week and day. This is the inverse of the function >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 214

New in version 3. 8

Thuộc tính lớp

date. min

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

date. max

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

date. resolution

The smallest possible difference between non-equal date objects, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 217

Thuộc tính phiên bản (chỉ đọc)

date. year

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

date. month

Between 1 and 12 inclusive

date. day

Between 1 and the number of days in the given month of the given year

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

Hoạt động

Kết quả

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 223. (2)

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

(3)

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

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

Notes

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

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

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

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

Trong ngữ cảnh Boolean, tất cả các đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32 được coi là đúng

Instance methods

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

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

Thí dụ

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

ngày. thời gian()

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

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

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

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

trong đó >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 35 cho ngày 1 tháng 1

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

Trả về thứ tự Gregorian proleptic của ngày, trong đó ngày 1 tháng 1 của năm 1 có thứ tự 1. Đối với bất kỳ đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32 d, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 209

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

Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 0 và Chủ Nhật là 6. Ví dụ: >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 257, Thứ Tư. Xem thêm >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 258

ngày. isoweekday()

Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 1 và Chủ Nhật là 7. Ví dụ: >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 259, Thứ Tư. Xem thêm >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 260, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 261

ngày. isocalendar()

Trả về đối tượng tuple có tên có ba thành phần. >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 11, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 263 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 264.

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

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

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

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

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

ngày. isoformat()

Trả về một chuỗi đại diện cho ngày ở định dạng ISO 8601, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 212

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

ngày. __str__()

Đối với một ngày d, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 267

ngày. thời gian()

Return a string representing the date

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

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

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

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

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

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

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

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

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

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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¶

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

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

Người xây dựng

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

Các đối số năm, tháng và ngày là bắt buộc. tzinfo có thể là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 490,

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

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

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

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

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

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

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 493 is raised

Mới trong phiên bản 3. 6. Added the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403

Equivalent to

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

See also >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 299, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1704 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1710

classmethod datetime. utcnow()

Return the current UTC date and time, with >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403

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

Cảnh báo

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

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

Trả về ngày và giờ địa phương tương ứng với dấu thời gian POSIX, chẳng hạn như được trả về bởi >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403 hoặc không được chỉ định, thì dấu thời gian được chuyển đổi thành ngày giờ địa phương của nền tảng và đối tượng >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7 được trả về là ngây thơ

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

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 200 có thể tăng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 418, nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi các hàm C >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 497 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1728 của nền tảng và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 497 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1728. Điều này thường bị giới hạn trong các năm từ 1970 đến 2038. Lưu ý rằng trên các hệ thống không phải POSIX bao gồm các giây nhuận trong khái niệm dấu thời gian của chúng, các giây nhuận bị bỏ qua bởi >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 418 thay vì >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 493 nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi các hàm nền tảng C >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 497 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1728. Raise >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 498 instead of >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 493 on >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 497 or >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1728 failure.

Đã 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 200

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 38

Cảnh báo

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

New in version 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1781 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1784

New in version 3. 8

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

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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 21

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

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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 34 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 38 inclusive

ngày giờ. tháng

Between 1 and 12 inclusive

ngày giờ. ngày

Between 1 and the number of days in the given month of the given year

ngày giờ. giờ

Trong >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1797

ngày giờ. giây

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

ngày giờ. micro giây

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

ngày giờ. tzinfo

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

ngày giờ. gấp

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

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

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

Hoạt động

Kết quả

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

(1)

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

(2)

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

(3)

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

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

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

  2. Tính datetime2 sao cho datetime2 + timedelta == datetime1. Ngoài ra, kết quả có thuộc tính >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 giống như ngày giờ đầu vào và không có điều chỉnh múi giờ nào được thực hiện ngay cả khi đầu vào biết

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

    Nếu cả hai đều ngây thơ hoặc cả hai đều biết và có cùng thuộc tính >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411 t sao cho >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 22. Không có điều chỉnh múi giờ nào được thực hiện trong trường hợp này

    Nếu cả hai đều biết và có các thuộc tính >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 khác nhau, thì >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 24 hoạt động như thể a và b lần đầu tiên được chuyển đổi thành thời gian biểu UTC ngây thơ trước. 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 được coi là nhỏ hơn datetime2 khi datetime1 trước datetime2 về thời gian

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

    Đã thay đổi trong phiên bản 3. 3. So sánh bình đẳng giữa các trường hợp >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7 nhận thức và ngây thơ không nâng cao >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 481 nếu đối tượng so sánh khác cũng không phải là đối tượng >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7. Tuy nhiên, thay vào đó, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 241 được trả về nếu đối tượng so sánh khác có thuộc tính >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 242. Móc này cung cấp cho các loại đối tượng ngày khác cơ hội thực hiện so sánh kiểu hỗn hợp. Nếu không, khi một đối tượng >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7 được so sánh với một đối tượng thuộc loại khác, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 481 được nâng lên trừ khi so sánh là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 475 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 247 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 248

Instance methods

ngày giờ. ngày()

Trả về đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 32 có cùng năm, tháng và ngày

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

Trả về đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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ờ

Mới trong phiên bản 3. 6. Added the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 22

Đã thay đổi trong phiên bản 3. 3. tz now can be omitted.

Đã 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403, trả về >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403, trả về >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403, trả về >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403 hoặc một đối tượng chuỗi,

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

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

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

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

trong đó >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 34 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 38 và điều chỉnh UTC vượt qua ranh giới năm

Cảnh báo

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

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 260, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 11, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 263 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 49, nếu >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 51, nếu >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 55, nếu >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 57, nếu >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 62 nếu >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 67

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 14 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 71

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 14, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 15 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 76

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 78

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

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

trên các nền tảng nơi hàm C >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 270 gọi, nhưng mà >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 174

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

Đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 290,

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

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

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

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 1797

thời gian. micro giây

Trong >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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

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

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

Các đối tượng >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0 với >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 475 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 247 hoặc >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 248

Changed in version 3. 3. Equality comparisons between aware and naive >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0 instances don’t raise >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 481.

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

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

Other constructor

classmethod time. fromisoformat(time_string)

Return a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0 corresponding to a time_string in any valid ISO 8601 format, with the following exceptions

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

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

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

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

ví dụ

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

New in version 3. 7

Changed in version 3. 11. Previously, this method only supported formats that could be emitted by >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 343.

Instance methods

time. thay thế(giờ=chính mình. hour , minute=self. phút , giây=chính mình. second , microsecond=self. microsecond , tzinfo=self. tzinfo , * , fold=0)

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

Mới trong phiên bản 3. 6. Added the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 296 argument.

time. isoformat(timespec='auto')

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

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

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

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

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 356, if >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 17 is 0 and >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 57 does not return >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 62 nếu >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 67

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 14 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 71

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 14, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 15 và >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 76

  • >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 78

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

Thí dụ

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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__()

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

thời gian. strftime(format)

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

time. __format__(định dạng)

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

time. utcoffset()

Nếu >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403, trả về >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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.

time. dst()

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

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

time. tzname()

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

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

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

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

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

class datetime. tzinfo

This is an abstract base class, meaning that this class should not be instantiated directly. Xác định một lớp con của >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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ể

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

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

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

Một phân lớp cụ thể của >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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. Exactly which methods are needed depends on the uses made of aware >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7 objects. If in doubt, simply implement all of them

tzinfo. utcoffset(dt)

Return offset of local time from UTC, as a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411 object that is positive east of UTC. Nếu giờ địa phương ở phía tây của UTC, điều này sẽ là âm

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

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

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

The default implementation of >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 57 raises >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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)

Return the daylight saving time (DST) adjustment, as a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411 object or >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403 if DST information isn’t known

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

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

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

must return the same result for every >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7 dt with >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 151 For sane >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 subclasses, this expression yields the time zone’s “standard offset”, which should not depend on the date or the time, but only on geographic location. The implementation of >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 153 relies on this, but cannot detect violations; it’s the programmer’s responsibility to ensure it. Nếu lớp con >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 179

or

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

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

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

tzinfo. tzname(dt)

Return the time zone name corresponding to the >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7 object dt, as a string. 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” are all valid replies. Return >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403 if a string name isn’t known. 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 chiếm thời gian ban ngày

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

When >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403 is passed, it’s up to the class designer to decide the best response. Ví dụ: trả về >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 178 to return the standard UTC offset, as there is no other convention for discovering the standard offset

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

There is one more >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 method that a subclass may wish to override

tzinfo. fromutc(dt)

This is called from the default >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 153 implementation. When called from that, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 181 is self, and dt’s date and time data are to be viewed as expressing a UTC time. The purpose of >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 188 is to adjust the date and time data, returning an equivalent datetime in self’s local time

Hầu hết các lớp con của >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 sẽ có thể kế thừa triển khai >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 188 mặc định mà không gặp sự cố. 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. An example of a time zone the default >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 188 implementation may not handle correctly in all cases is one where the standard offset (from UTC) depends on the specific date and time passed, which can happen for political reasons. 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 (daylight time) back to 1. 00 (standard time) again. Local times of the form 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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))

See also

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

The >>> from datetime import timedelta >>> delta1 = timedelta(seconds=57) >>> delta2 = timedelta(hours=25, seconds=2) >>> delta2 != delta1 True >>> delta2 == 5 False 7 module has a basic >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 8 class (for handling arbitrary fixed offsets from UTC) and its >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7111 attribute (a UTC timezone instance)

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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. It is updated periodically to reflect changes made by political bodies to time zone boundaries, UTC offsets, and daylight-saving rules

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

Lớp >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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)

The offset argument must be specified as a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 411 object representing the difference between the local time and UTC. It must be strictly between >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 126 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 127, otherwise >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 8 instance is constructed

The dt argument is ignored. The return value is a >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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.

timezone. tzname(dt)

Return the fixed value specified when the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7129 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7132, not >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 4 set to >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7139

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

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7140 versus >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7141

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

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

Usage

Chuyển đổi đối tượng thành một chuỗi theo một định dạng nhất định

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 "<stdin>", line 1, in <module> 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

Signature

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

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

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7140 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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

Nghĩa

Thí dụ

Notes

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7162

Weekday as locale’s full name

Sunday, Monday, …, Saturday (en_US);

Sonntag, Montag, …, Samstag (de_DE)

(1)

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7178

Time zone name (empty string if the object is naive)

(trống), UTC, GMT

(6)

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7185

A literal >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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

Nghĩa

Thí dụ

Notes

>>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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. Week 01 is the week containing Jan 4

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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7187, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7189 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 0 module’s >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 242 method

Đối với phương thức lớp >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7146, giá trị mặc định là >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 906

For >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7150 may raise >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 917, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 918, or >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 919; use >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7141 method, the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7141 method, the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7176 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 is transformed into a string of the form >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7177, where >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 67 is a 2-digit string giving the number of UTC offset hours, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 938 is a 2-digit string giving the number of UTC offset minutes, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 939 is a 2-digit string giving the number of UTC offset seconds and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 940 is a 6-digit string giving the number of UTC offset microseconds. The >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 940 part is omitted when the offset is a whole number of seconds and both the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 940 and the >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 939 part is omitted when the offset is a whole number of minutes. 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 945, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 952.

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

    In >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7140, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7178 is replaced by an empty string if >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 165 returns >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 403; otherwise >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7178 is replaced by the returned value, which must be a string

    >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 962 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 964, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 962, and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7141 method, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7180 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7180 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7181, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7187 and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> 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 "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7164, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7167, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7170, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7171, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7173, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7174, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 992, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7180, >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7181, and >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int' 7188. Format >>> delta2 > delta1 True >>> delta2 > 5 Traceback (most recent call last): File "<stdin>", line 1, in <module> 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ủ đề