Mặc dù số học ngày và giờ được hỗ trợ, trọng tâm của việc triển khai là trích xuất thuộc tính hiệu quả để định dạng và thao tác đầu ra
Xem thêm
Mô-đun>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False9
Các chức năng liên quan đến lịch chung
Mô-đun>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0
Thời gian truy cập và chuyển đổi
Mô-đun>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1
Múi giờ cụ thể đại diện cho cơ sở dữ liệu múi giờ IANA
ngày đóng góiThư viện của bên thứ ba với múi giờ mở rộng và hỗ trợ phân tích cú pháp
Đối tượng nhận thức và ngây thơ¶
Các đối tượng ngày và giờ có thể được phân loại là "nhận biết" hoặc "ngây thơ" tùy thuộc vào việc chúng có bao gồm thông tin múi giờ hay không
Với kiến thức đầy đủ về các điều chỉnh thời gian chính trị và thuật toán hiện hành, chẳng hạn như múi giờ và thông tin về thời gian tiết kiệm ánh sáng ban ngày, một đối tượng nhận biết có thể định vị chính nó so với các đối tượng nhận biết khác. Một đối tượng nhận thức đại diện cho một thời điểm cụ thể không thể giải thích được. 1
Một đối tượng ngây thơ không chứa đủ thông tin để định vị chính nó một cách rõ ràng so với các đối tượng ngày/giờ khác. Việc một đối tượng ngây thơ đại diện cho Giờ phối hợp quốc tế [UTC], giờ địa phương hay thời gian ở một số múi giờ khác hoàn toàn phụ thuộc vào chương trình, giống như việc một số cụ thể đại diện cho mét, dặm hay khối lượng hay không là tùy thuộc vào chương trình. Các đối tượng ngây thơ dễ hiểu và dễ làm việc với cái giá phải trả là bỏ qua một số khía cạnh của thực tế
Đối với các ứng dụng yêu cầu các đối tượng nhận biết, các đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 có thuộc tính thông tin múi giờ tùy chọn,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4, có thể được đặt thành một thể hiện của một lớp con của lớp trừu tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4. Các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 này nắm bắt thông tin về độ lệch so với thời gian UTC, tên múi giờ và liệu thời gian tiết kiệm ánh sáng ban ngày có hiệu lực hay không
Chỉ có một lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 cụ thể, lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8, được cung cấp bởi mô-đun
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7. Lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 có thể đại diện cho các múi giờ đơn giản với độ lệch cố định từ UTC, chẳng hạn như chính UTC hoặc các múi giờ EST và EDT của Bắc Mỹ. Hỗ trợ các múi giờ ở mức độ chi tiết sâu hơn tùy thuộc vào ứng dụng. Các quy tắc điều chỉnh thời gian trên toàn thế giới mang tính chính trị hơn là hợp lý, thay đổi thường xuyên và không có tiêu chuẩn nào phù hợp cho mọi ứng dụng ngoài UTC
Hằng số¶
Mô-đun
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 xuất các hằng số saungày giờ. THÁNG NĂM ¶
Số năm nhỏ nhất được phép trong một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 hoặc
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'34 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'35ngày giờ. MAX NĂM ¶
Số năm lớn nhất được phép trong một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 hoặc
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'38 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'39ngày giờ. UTC ¶
Bí danh cho múi giờ UTC đơn lẻ
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'10
Mới trong phiên bản 3. 11
Các loại có sẵn¶
lớp ngày giờ. ngàyMột ngày ngây thơ được lý tưởng hóa, giả sử rằng lịch Gregorian hiện tại luôn có hiệu lực. Thuộc tính.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'11,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'12 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'13lớp ngày giờ. thời gian
Thời gian lý tưởng hóa, không phụ thuộc vào bất kỳ ngày cụ thể nào, giả sử rằng mỗi ngày có chính xác 24*60*60 giây. [Không có khái niệm “giây nhuận” ở đây. ] Thuộc tính.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'14,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'15,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'16,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'17 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4lớp ngày giờ. ngày giờ
Một sự kết hợp của một ngày và một thời gian. Thuộc tính.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'11,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'12,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'13,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'14,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'15,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'16,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'17 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4lớp ngày giờ. đồng hồ thời gian
Khoảng thời gian thể hiện sự khác biệt giữa hai phiên bản
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 hoặc
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 đối với độ phân giải micro giâylớ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 False7 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 để cung cấp khái niệm điều chỉnh thời gian có thể tùy chỉnh [ví dụ: để tính múi giờ và/hoặc thời gian tiết kiệm ánh sáng ban ngày]lớp ngày giờ. múi giờ
Một lớp triển khai lớp cơ sở trừu tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 dưới dạng phần bù cố định từ UTC
Mới trong phiên bản 3. 2
Các đối tượng của các loại này là bất biến
quan hệ phân lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
Tài sản chung¶
Các loại
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 có chung những đặc điểm này
Các đối tượng của các loại này là bất biến
Các đối tượng thuộc loại này có thể băm được, nghĩa là chúng có thể được sử dụng làm khóa từ điển
Các đối tượng thuộc loại này hỗ trợ tẩy hiệu quả thông qua mô-đun
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
97
Xác định xem một đối tượng là Aware hay Naive¶
Các đối tượng thuộc loại
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 luôn ngây thơ
Một đối tượng thuộc loại
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 hoặc
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 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 False7 d nhận biết nếu cả hai điều sau đây đều đúng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
402 không phải là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
404 không trả lại>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403
Mặt khác, d là ngây thơ
Một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 t nhận biết được nếu cả hai điều kiện sau đều đúng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
407 không phải là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
409 không trả lại>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403
Nếu không, t là ngây thơ
Sự khác biệt giữa nhận thức và ngây thơ không áp dụng cho các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 Đối tượng¶
Một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 đại diện cho một khoảng thời gian, sự khác biệt giữa hai ngày hoặc thời gianlớp ngày giờ. timedelta[ngày=0, seconds=0, microseconds=0, milliseconds=0, minutes=0, hours=0, weeks=0]¶
Tất cả các đối số là tùy chọn và mặc định là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'414. Các đối số có thể là số nguyên hoặc số float và có thể dương hoặc âm
Chỉ ngày, giây và micro giây được lưu trữ nội bộ. Các đối số được chuyển đổi thành các đơn vị đó
Một phần nghìn giây được chuyển đổi thành 1000 micro giây
Một phút được chuyển thành 60 giây
Một giờ được chuyển đổi thành 3600 giây
Một tuần được chuyển đổi thành 7 ngày
và ngày, giây và micro giây sau đó được chuẩn hóa để biểu diễn là duy nhất, với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
415>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
416 [số giây trong một ngày]>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
417
Ví dụ sau đây minh họa cách mọi đối số ngoài ngày, giây và micro giây được “hợp nhất” và chuẩn hóa thành ba thuộc tính kết quả đó
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
Nếu bất kỳ đối số nào là số float và có micro giây phân số, thì micro giây phân số còn lại từ tất cả các đối số sẽ được kết hợp và tổng của chúng được làm tròn đến micro giây gần nhất bằng cách sử dụng bộ ngắt kết nối nửa vòng đến chẵn. If no argument is a float, the conversion and normalization processes are exact [no information is lost]
Nếu giá trị chuẩn hóa của ngày nằm ngoài phạm vi được chỉ định, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418 được tăng lên
Lưu ý rằng việc chuẩn hóa các giá trị âm lúc đầu có thể gây ngạc nhiên. Ví dụ
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'2
Thuộc tính lớp
đồng bằng thời gian. min ¶Đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 tiêu cực nhất,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'420đồng bằng thời gian. tối đa ¶
Đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 tích cực nhất,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'422đồng bằng thời gian. độ phân giải ¶
The smallest possible difference between non-equal
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 objects,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'424
Lưu ý rằng, do chuẩn hóa, ________ 5425 > ________ 5426.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'427 không thể biểu diễn dưới dạng đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411
Thuộc tính phiên bản [chỉ đọc]
Thuộc tính
Value
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'429
Giữa -999999999 và bao gồm cả 999999999
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'430
Bao gồm từ 0 đến 86399
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'431
Bao gồm từ 0 đến 999999
hoạt động được hỗ trợ
Operation
Kết quả
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'432
Tổng của t2 và t3. Sau đó t1-t2 == t3 và t1-t3 == t2 là đúng. [1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'433
Difference of t2 and t3. Sau đó t1 == t2 - t3 và t2 == t1 + t3 là đúng. [1][6]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'434
Delta 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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'435
Nói chung, t1 * i == t1 * [i-1] + t1 là đúng. [1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'436
Delta nhân với một số float. The result is rounded to the nearest multiple of 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 "", line 1, in 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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'438
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'439
Delta 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. resolution using round-half-to-even
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'440 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'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 "", line 1, in 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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411. [3]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'444
Tính thương và số dư.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'445 [3] và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'448
Trả về một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 có cùng giá trị. [2]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'450
equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411[-t1. 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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'452
tương đương với +t khi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'453 và -t khi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'454. [2]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'455
Trả về một chuỗi ở dạng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'456, trong đó D là số âm cho số âm của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'457. [5]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'458
Trả về một biểu diễn chuỗi của đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 dưới dạng lệnh gọi hàm tạo với các giá trị thuộc tính chính tắc
ghi chú
Điều này là chính xác nhưng có thể tràn
Điều này là chính xác và không thể tràn
Chia cho 0 tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
460-timedelta. max không thể biểu diễn dưới dạng đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411Biểu diễn chuỗi của đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 được chuẩn hóa tương tự như biểu diễn bên trong của chúng. Điều này dẫn đến kết quả hơi bất thường đối với timedelta âm. Ví dụ>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17Biểu thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
463 sẽ luôn bằng biểu thức>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
464 trừ khi t3 bằng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
425;
Ngoài các hoạt động được liệt kê ở trên, các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 hỗ trợ một số phép cộng và phép trừ với các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 và
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 [xem bên dưới]
Đã thay đổi trong phiên bản 3. 2. Phép chia tầng và phép chia thực sự của một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 cho một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 khác hiện được hỗ trợ, cũng như các phép toán còn lại và hàm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'471. Phép chia và phép nhân thực của đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 với đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'438 hiện đã được hỗ trợ.
So sánh các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 được hỗ trợ, với một số lưu ý
Các so sánh
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'475 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'476 luôn trả về một
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'477, bất kể loại đối tượng được so sánh
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
Đối với tất cả các phép so sánh khác [chẳng hạn như
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'478 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'479], khi một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 được so sánh với một đối tượng thuộc loại khác, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'481 được nâng lên
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
Trong ngữ cảnh Boolean, một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 được coi là đúng khi và chỉ khi nó không bằng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'483
Phương thức sơ thẩm
đồng bằng thời gian. total_seconds[] ¶Trả về tổng số giây có trong khoảng thời gian. Tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'484. Đối với các đơn vị khoảng thời gian không phải là giây, hãy sử dụng biểu mẫu chia trực tiếp [e. g.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'485]
Note that for very large time intervals [greater than 270 years on most platforms] this method will lose microsecond accuracy
Mới trong phiên bản 3. 2
Ví dụ về cách sử dụng. >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411¶
Một ví dụ bổ sung về chuẩn hóa
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'3
Ví dụ về số học
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 Đối tượng¶
Một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 đại diện cho một ngày [năm, tháng và ngày] trong lịch được lý tưởng hóa, lịch Gregorian hiện tại được mở rộng vô thời hạn theo cả hai hướng
Ngày 1 tháng 1 của năm 1 được gọi là ngày 1, ngày 2 tháng 1 của năm 1 được gọi là ngày 2, v.v. 2
lớp ngày giờ. ngày[năm , tháng, day]¶Tất cả các đối số là bắt buộc. Các đối số phải là số nguyên, trong các phạm vi sau
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
490>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
491>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
492
Nếu một đối số nằm ngoài các phạm vi đó được đưa ra, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 được nêu ra
Các hàm tạo khác, tất cả các phương thức của lớp
classmethod date. today[] ¶Return the current local date
This is equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'494classmethod date. fromtimestamp[timestamp] ¶
Return the local date corresponding to the POSIX timestamp, such as is returned by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'495
This may raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418, if the timestamp is out of the range of values supported by the platform C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'497 function, and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'498 on
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'497 failure. It’s common for this to be restricted to years from 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'200
Changed in version 3. 3. Raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418 instead of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 if the timestamp is out of the range of values supported by the platform C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'497 function. Raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'498 instead of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 on
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'497 failure. classmethod date. 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 "", line 1, in 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 "", line 1, in 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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'209classmethod date. fromisoformat[date_string] ¶
Return a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'211]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'71
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 "", line 1, in 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 "", line 1, in 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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'214
New in version 3. 8
Thuộc tính lớp
ngày. min ¶The earliest representable date,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'215date. max ¶
The latest representable date,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'216date. resolution ¶
The smallest possible difference between non-equal date objects,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'34 and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'38 inclusivedate. 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ợ
Operation
Kết quả
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'220
date2 will be
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'221 days after date1. [1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'222
Tính date2 sao cho
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'223. [2]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'224
[3]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'225
date1 được coi là nhỏ hơn date2 khi date1 trước date2 về thời gian. [4]
ghi chú
date2 được di chuyển về phía trước theo thời gian nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
226 hoặc lùi lại nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
227. Sau đó>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
228.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
229 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
230 bị bỏ qua.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418 được nâng lên nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
232 sẽ nhỏ hơn>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
34 hoặc lớn hơn>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
38>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
229 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
230 bị bỏ quaĐiều này là chính xác và không thể tràn. timedelta. giây và timedelta. micro giây là 0 và date2 + timedelta == date1 sau
Nói cách khác,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
225 khi và chỉ khi>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
238. Date comparison raises>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 if the other comparand isn’t also a>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 object. Tuy nhiên, thay vào đó,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
241 được trả về nếu đối tượng so sánh khác có thuộc tính>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
242. Móc này cung cấp cho các loại đối tượng ngày khác cơ hội thực hiện so sánh kiểu hỗn hợp. Nếu không, khi một đối tượng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32 được so sánh với một đối tượng thuộc loại khác,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 được nâng lên trừ khi so sánh là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
475 hoặc>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
476. Các trường hợp sau lần lượt trả về>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
247 hoặc>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
248
Trong ngữ cảnh Boolean, tất cả các đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 được coi là đúng
Phương thức sơ thẩm
ngày. replace[year=self. year , month=self. tháng , ngày=chính mình. ngày] ¶Trả về một ngày có cùng giá trị, ngoại trừ các tham số được cung cấp giá trị mới theo bất kỳ đối số từ khóa nào được chỉ định
Thí dụ
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'9ngày. thời gian[] ¶
Return a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'250 such as returned by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'251
Giờ, phút và giây là 0 và cờ DST là -1
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'252 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'40
trong đó
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'253 là số ngày trong năm hiện tại bắt đầu bằng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'35 cho ngày 1 tháng 1ngày. toordinal[] ¶
Return the proleptic Gregorian ordinal of the date, where January 1 of year 1 has ordinal 1. Đối với bất kỳ đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 d,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'209ngày. ngày trong tuần[] ¶
Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 0 và Chủ nhật là 6. Ví dụ:
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'257, Thứ Tư. Xem thêm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'258ngày. ngày trong tuần[] ¶
Trả về ngày trong tuần dưới dạng số nguyên, trong đó Thứ Hai là 1 và Chủ nhật là 7. Ví dụ:
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'259, Thứ Tư. Xem thêm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'260,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'261date. isocalendar[] ¶
Return a named tuple object with three components.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'11,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'263 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'264.
The ISO calendar is a widely used variant of the Gregorian calendar. 3
The ISO year consists of 52 or 53 full weeks, and where a week starts on a Monday and ends on a Sunday. The first week of an ISO year is the first [Gregorian] calendar week of a year containing a Thursday. This is called week number 1, and the ISO year of that Thursday is the same as its Gregorian year
For example, 2004 begins on a Thursday, so the first week of ISO year 2004 begins on Monday, 29 Dec 2003 and ends on Sunday, 4 Jan 2004
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'41
Đã thay đổi trong phiên bản 3. 9. Kết quả đã thay đổi từ một bộ thành bộ có tên .
date. isoformat[] ¶Return a string representing the date in ISO 8601 format,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'212
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'42date. __str__[] ¶
For a date d,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'266 is equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'267date. ctime[] ¶
Return a string representing the date
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'43
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'268 is equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'44
on platforms where the native C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'269 function [which
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'270 invokes, but which
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'271 does not invoke] conforms to the C standarddate. strftime[format] ¶
Return a string representing the date, controlled by an explicit format string. Format codes referring to hours, minutes or seconds will see 0 values. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .
date. __format__[format] ¶Same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'272. This makes it possible to specify a format string for a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 object in formatted string literals and when using
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'274. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .
Examples of Usage. >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
32¶
Example of counting days to an event
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'45
More examples of working with
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'46
>>> from datetime import timedelta
>>> delta1 = timedelta[seconds=57]
>>> delta2 = timedelta[hours=25, seconds=2]
>>> delta2 != delta1
True
>>> delta2 == 5
False
7 Objects¶
A
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object is a single object containing all the information from a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 object and a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object
Like a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 object,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 assumes the current Gregorian calendar extended in both directions; like a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 assumes there are exactly 3600*24 seconds in every day
Constructor
class datetime. datetime[year , month , day , hour=0 , minute=0 , second=0 , microsecond=0 , tzinfo=None , * , fold=0] ¶The year, month and day arguments are required. tzinfo may be
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, or an instance of a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass. The remaining arguments must be integers in the following ranges
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
490,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
491,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
492,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
290,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
291,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
292,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
293,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
294
Nếu một đối số nằm ngoài các phạm vi đó được đưa ra, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 được nêu ra
New in version 3. 6. Added the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'296 argument.
Các hàm tạo khác, tất cả các phương thức của lớp
classmethod datetime. today[] ¶Trả về ngày giờ địa phương hiện tại, với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403
Equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'47
See also
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'299,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'200
This method is functionally equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'299, but without a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1702 parameterclassmethod datetime. now[tz=None] ¶
Return the current local date and time
If optional argument tz is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 or not specified, this is like
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1704, but, if possible, supplies more precision than can be gotten from going through a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'495 timestamp [for example, this may be possible on platforms supplying the C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1706 function]
If tz is not
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, it must be an instance of a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass, and the current date and time are converted to tz’s time zone
This function is preferred over
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1704 and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1710classmethod datetime. utcnow[] ¶
Return the current UTC date and time, with
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403
This is like
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'299, but returns the current UTC date and time, as a naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object. An aware current UTC datetime can be obtained by calling
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1715. See also
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'299
Warning
Because naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 objects are treated by many
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 methods as local times, it is preferred to use aware datetimes to represent times in UTC. As such, the recommended way to create an object representing the current time in UTC is by calling
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1715classmethod datetime. fromtimestamp[timestamp , tz=None] ¶
Return the local date and time corresponding to the POSIX timestamp, such as is returned by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'495. If optional argument tz is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 or not specified, the timestamp is converted to the platform’s local date and time, and the returned
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object is naive
If tz is not
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, it must be an instance of a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass, and the timestamp is converted to tz’s time zone
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'200 may raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418, if the timestamp is out of the range of values supported by the platform C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'497 or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1728 functions, and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'498 on
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'497 or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1728 failure. It’s common for this to be restricted to years in 1970 through 2038. Note that on non-POSIX systems that include leap seconds in their notion of a timestamp, leap seconds are ignored by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'200, and then it’s possible to have two timestamps differing by a second that yield identical
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 objects. This method is preferred over
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1734
Changed in version 3. 3. Raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418 instead of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 if the timestamp is out of the range of values supported by the platform C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'497 or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1728 functions. Raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'498 instead of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 on
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'497 or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1728 failure.
Đã thay đổi trong phiên bản 3. 6. ______7200 có thể trả về các phiên bản với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'296 được đặt thành 1. classmethod datetime. utcfromtimestamp[timestamp] ¶
Return the UTC
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 corresponding to the POSIX timestamp, with
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403. [The resulting object is naive. ]
Điều này có thể tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418, nếu dấu thời gian nằm ngoài phạm vi giá trị được hỗ trợ bởi hàm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1728 của nền tảng C và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'498 khi lỗi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1728. It’s common for this to be restricted to years in 1970 through 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 False7, hãy gọi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'200
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'48
On the POSIX compliant platforms, it is equivalent to the following expression
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'49
except the latter formula always supports the full years range. between
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'34 and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'38 inclusive
Warning
Bởi vì các đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 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 False7 coi là giờ địa phương, nên sử dụng thời gian nhận thức để biểu thị thời gian trong UTC. Do đó, cách được khuyến nghị để tạo một đối tượng đại diện cho một dấu thời gian cụ thể trong UTC là gọi số
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1758
Đã thay đổi trong phiên bản 3. 3. Raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418 instead of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 if the timestamp is out of the range of values supported by the platform C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1728 function. Raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'498 instead of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 on
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1728 failure. classmethod datetime. fromordinal[ordinal] ¶
Return the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 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 "", line 1, in 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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1767. The hour, minute, second and microsecond of the result are all 0, and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403phương thức lớp ngày giờ. combine[date , time , tzinfo=self. tzinfo] ¶
Return a new
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object whose date components are equal to the given
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 object’s, and whose time components are equal to the given
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object’s. Nếu đối số tzinfo được cung cấp, giá trị của nó được sử dụng để đặt thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 của kết quả, nếu không thì thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 của đối số thời gian được sử dụng
Đối với bất kỳ đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 d,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1776. If date is a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 object, its time components and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 attributes are ignored
Changed in version 3. 6. Added the tzinfo argument.
classmethod datetime. fromisoformat[date_string] ¶Return a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 corresponding to a date_string in any valid ISO 8601 format, with the following exceptions
Time zone offsets may have fractional seconds
The
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1780 separator may be replaced by any single unicode characterNgày thứ tự hiện không được hỗ trợ
Fractional hours and minutes are not supported
Examples
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'20
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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1781 or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1782. classmethod datetime. 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 False7 tương ứng với ngày theo lịch ISO được chỉ định theo năm, tuần và ngày. The non-date components of the datetime are populated with their normal default values. This is the inverse of the function
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1784
New in version 3. 8
classmethod datetime. strptime[date_string , format] ¶Return a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 corresponding to date_string, parsed according to format
This is equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'21
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 is raised if the date_string and format can’t be parsed by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1787 or if it returns a value which isn’t a time tuple. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .
Thuộc tính lớp
datetime. min ¶Đạ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 False7,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1789ngày giờ. tối đa ¶
The latest representable
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1791ngày giờ. resolution ¶
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 False7 không bằng nhau,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'424
Thuộc tính phiên bản [chỉ đọc]
datetime. năm ¶Between
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'34 and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'38 inclusivengà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
datetime. giờ ¶In
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1796ngày giờ. minute ¶
Trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1797datetime. giây ¶
Trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1797datetime. microsecond ¶
In
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1799ngày giờ. tzinfo ¶
The object passed as the tzinfo argument to the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 constructor, or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 if none was passeddatetime. gấp ¶
In
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False02. Used to disambiguate wall times during a repeated interval. [Một khoảng thời gian lặp lại xảy ra khi đồng hồ 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ị. ] The value 0 [1] represents the earlier [later] of the two moments with the same wall time representation
Mới trong phiên bản 3. 6
hoạt động được hỗ trợ
Operation
Kết quả
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False03
[1]
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False04
[2]
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False05
[3]
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False06
Compares
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 to
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7. [4]
datetime2 là khoảng thời gian của timedelta bị xóa khỏi datetime1, tiến về phía trước nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
221 > 0 hoặc lùi lại nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
221 < 0. The result has the same>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute as the input datetime, and datetime2 - datetime1 == timedelta after.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
418 is raised if datetime2. năm sẽ nhỏ hơn>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
34 hoặc lớn hơn>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
38. Note that no time zone adjustments are done even if the input is an aware objectComputes the datetime2 such that datetime2 + timedelta == datetime1. As for addition, the result has the same
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute as the input datetime, and no time zone adjustments are done even if the input is awareSubtraction of a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 from a>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 is defined only if both operands are naive, or if both are aware. If one is aware and the other is naive,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 is raisedNếu cả hai đều ngây thơ hoặc cả hai đều biết và có cùng thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4, các thuộc tính>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 sẽ bị bỏ qua và kết quả là một đối tượng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
411 t sao cho>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
22. Không có điều chỉnh múi giờ nào được thực hiện trong trường hợp nàyIf both are aware and have different
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attributes,>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
24 acts as if a and b were first converted to naive UTC datetimes first. Kết quả là>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
25 ngoại trừ việc triển khai không bao giờ bị tràndatetime1 is considered less than datetime2 when datetime1 precedes datetime2 in time
If one comparand is naive and the other is aware,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 is raised if an order comparison is attempted. For equality comparisons, naive instances are never equal to aware instancesIf both comparands are aware, and have the same
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute, the common>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attribute is ignored and the base datetimes are compared. If both comparands are aware and have different>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 attributes, the comparands are first adjusted by subtracting their UTC offsets [obtained from>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
30]Changed in version 3. 3. Equality comparisons between aware and naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 instances don’t raise>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481.Note
In order to stop comparison from falling back to the default scheme of comparing object addresses, datetime comparison normally raises
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 if the other comparand isn’t also a>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 object. However,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
241 is returned instead if the other comparand has a>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
242 attribute. This hook gives other kinds of date objects a chance at implementing mixed-type comparison. If not, when a>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 object is compared to an object of a different type,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
481 is raised unless the comparison is>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
475 or>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
476. The latter cases return>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
247 or>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
248, respectively
Phương thức sơ thẩm
datetime. date[] ¶Trả về đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 có cùng năm, tháng và ngàydatetime. time[] ¶
Return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object with same hour, minute, second, microsecond and fold.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403. See also method
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False47
Changed in version 3. 6. The fold value is copied to the returned
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object. ngày giờ. timetz[] ¶
Return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object with same hour, minute, second, microsecond, fold, and tzinfo attributes. See also method
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False50
Changed in version 3. 6. The fold value is copied to the returned
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 object. ngày giờ. replace[year=self. year , month=self. month , day=self. ngày , giờ=chính mình. hour , minute=self. minute , second=self. second , microsecond=self. microsecond , tzinfo=self. tzinfo , * , fold=0] ¶
Return a datetime with the same attributes, except for those attributes given new values by whichever keyword arguments are specified. Note that
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False52 can be specified to create a naive datetime from an aware datetime with no conversion of date and time data
New in version 3. 6. Added the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'296 argument. ngày giờ. astimezone[tz=None] ¶
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 False7 với thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 mới tz, điều chỉnh dữ liệu ngày và giờ để kết quả có cùng thời gian UTC với chính nó, nhưng theo giờ địa phương của tz
Nếu được cung cấp, tz phải là một thể hiện của lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 và các phương thức
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 và
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 của nó không được trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403. If self is naive, it is presumed to represent time in the system timezone
If called without arguments [or with
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False60] the system local timezone is assumed for the target timezone. Thuộc tính
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False61 của phiên bản datetime đã chuyển đổi sẽ được đặt thành phiên bản của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 với tên vùng và phần bù thu được từ HĐH
If
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False63 is tz,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False64 is equal to self. no adjustment of date or time data is performed. Else the result is local time in the timezone tz, representing the same UTC time as self. sau
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False65,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False66 sẽ có cùng dữ liệu ngày và giờ như
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False67
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 False68. 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 False69
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 False70 mặc định có thể được ghi đè trong lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 để ảnh hưởng đến kết quả được trả về bởi
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72. Ignoring error cases,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 acts like
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'22
Đã thay đổi trong phiên bản 3. 3. tz bây giờ có thể được bỏ qua.
Đã thay đổi trong phiên bản 3. 6. Phương thức
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 hiện có thể được gọi trên các phiên bản ngây thơ được cho là đại diện cho giờ địa phương của hệ thống. datetime. utcoffset[] ¶
If
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 is
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, returns
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, else returns
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False78, and raises an exception if the latter doesn’t return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 or a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 object with magnitude less than one day
Đã thay đổi trong phiên bản 3. 7. The UTC offset is not restricted to a whole number of minutes.
datetime. dst[] ¶Nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, ngược lại trả về
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False84 và đưa ra một ngoại lệ nếu cái sau không trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 hoặc một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 có cường độ nhỏ hơn một ngày
Changed in version 3. 7. The DST offset is not restricted to a whole number of minutes.
ngày giờ. tzname[] ¶Nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, ngược lại trả về
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False90, đưa ra một ngoại lệ nếu cái sau không trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 hoặc một đối tượng chuỗi,datetime. thời gian[] ¶
Return a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'250 such as returned by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'251
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'252 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'23
trong đó
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'253 là số ngày trong năm hiện tại bắt đầu bằng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'35 cho ngày 1 tháng 1. The
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 flag of the result is set according to the
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 method.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 hoặc
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 được đặt thành
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'04; datetime. utctimetuple[] ¶
Nếu
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 thể hiện d là ngây thơ, thì điều này giống với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'252 ngoại trừ việc
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 bị buộc về 0 bất kể giá trị trả về của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'13 là gì. DST không bao giờ có hiệu lực trong thời gian UTC
If d is aware, d is normalized to UTC time, by subtracting
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'14, and a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'250 for the normalized time is returned.
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 buộc phải 0. Lưu ý rằng một
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418 có thể được nâng lên nếu d. year was
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'34 or
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'38 and UTC adjustment spills over a year boundary
Warning
Bởi vì các đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 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 False7 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; . 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 False7 ngây thơ đại diện cho UTC, hãy sử dụng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'24 để làm cho nó biết, tại thời điểm đó bạn có thể sử dụng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'25datetime. toordinal[] ¶
Return the proleptic Gregorian ordinal of the date. The same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'26datetime. timestamp[] ¶
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 False7. The return value is a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'438 similar to that returned by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'495
Naive
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instances are assumed to represent local time and this method relies on the platform C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'31 function to perform the conversion. Vì
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 hỗ trợ phạm vi giá trị rộng hơn so với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'31 trên nhiều nền tảng nên phương pháp này có thể tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'418 cho những thời điểm xa trong quá khứ hoặc xa trong tương lai
For aware
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instances, the return value is computed as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'24
Mới trong phiên bản 3. 3
Đã thay đổi trong phiên bản 3. 6. The
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'36 method uses the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'296 attribute to disambiguate the times during a repeated interval.
Note
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 False7 ngây thơ đại diện cho thời gian UTC. If your application uses this convention and your system timezone is not set to UTC, you can obtain the POSIX timestamp by supplying
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'39
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'25
or by calculating the timestamp directly
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'26datetime. ngày trong tuần[] ¶
Return the day of the week as an integer, where Monday is 0 and Sunday is 6. Giống như
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'40. Xem thêm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'258ngà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. The same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'42. See also
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'260,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'261ngày giờ. isocalendar[] ¶
Trả về một bộ có tên với ba thành phần.
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'11,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'263 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'264. The same as
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'48. datetime. isoformat[sep=', timespec='auto']¶
Return a string representing the date and time in ISO 8601 format
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
49, if>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 is not 0>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
51, nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 là 0
If
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 does not return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, a string is appended, giving the UTC offset
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
55, if>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 is not 0>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
57, nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 là 0
Examples
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'27
The optional argument sep [default
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'59] is a one-character separator, placed between the date and time portions of the result. For example
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'28
Đối số tùy chọn timespec chỉ định số lượng thành phần bổ sung của thời gian cần đưa vào [mặc định là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'60]. It can be one of the following
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
60. Giống như>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
62 nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 là 0, giống như>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
64 nếu không>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
65. Bao gồm>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14 ở định dạng hai chữ số>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
67>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
68. Bao gồm>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
15 ở định dạng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
71>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
62. Include>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
15, and>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
16 in>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
76 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
77. Bao gồm toàn thời gian, nhưng cắt ngắn phần thứ hai thành mili giây.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
78 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
64. Bao gồm toàn thời gian ở định dạng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
80
Note
Excluded time components are truncated, not rounded
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 will be raised on an invalid timespec argument
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'29
Mới trong phiên bản 3. 6. Đã thêm đối số thông số thời gian.
datetime. __str__[] ¶For a
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instance d,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'266 is equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'84ngày giờ. thời gian[] ¶
Return a string representing the date and time
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'170
The output string will not include time zone information, regardless of whether the input is aware or naive
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'268 is equivalent to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'44
on platforms where the native C
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'269 function [which
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'270 invokes, but which
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'88 does not invoke] conforms to the C standardngày giờ. strftime[format] ¶
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. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .
datetime. __format__[định dạng] ¶Giống như
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'89. Điều này cho phép chỉ định một chuỗi định dạng cho một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 trong các chuỗi ký tự được định dạng và khi sử dụng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'274. For a complete list of formatting directives, see strftime[] and strptime[] Behavior .
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
7¶
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 False7
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'172
The example below defines a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass capturing time zone information for Kabul, Afghanistan, which used +4 UTC until 1945 and then +4. 30 UTC thereafter
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'173
Usage of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'95 from above
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'174
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0 Objects¶
Đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 đại diện cho thời gian trong ngày [cục bộ], không phụ thuộc vào bất kỳ ngày cụ thể nào và có thể điều chỉnh thông qua đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4class datetime. time[hour=0 , minute=0 , second=0 , microsecond=0 , tzinfo=None , * , fold=0] ¶
Tất cả các đối số là tùy chọn. tzinfo may be
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, or an instance of a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass. The remaining arguments must be integers in the following ranges
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
290,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
291,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
292,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
293,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
294
If an argument outside those ranges is given,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 is raised. Tất cả mặc định là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'414 ngoại trừ tzinfo, mặc định là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403
Thuộc tính lớp
thời gian. min ¶Đại diện sớm nhất
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'310thời gian. max ¶
Đại diện mới nhất
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'312thời gian. độ phân giải ¶
The smallest possible difference between non-equal
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'424, although note that arithmetic on
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects is not supported
Thuộc tính phiên bản [chỉ đọc]
thời gian. giờ ¶In
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1796time. minute ¶
Trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1797time. second ¶
Trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1797time. micro giây ¶
In
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1799thời gian. tzinfo ¶
Đối tượng được truyền dưới dạng đối số tzinfo cho hàm tạo
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 nếu không có đối số nào được truyềnthời gian. gấp ¶
In
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False02. Used to disambiguate wall times during a repeated interval. [Một khoảng thời gian lặp lại xảy ra khi đồng hồ 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ị. ] The value 0 [1] represents the earlier [later] of the two moments with the same wall time representation
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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 hỗ trợ so sánh giữa
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0, trong đó a được coi là nhỏ hơn b khi a đứng trước b về thời gian. Nếu một người so sánh ngây thơ và người kia nhận thức được, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'481 sẽ được nâng lên nếu cố gắng so sánh đơn hàng. Để so sánh bình đẳng, các trường hợp ngây thơ không bao giờ bằng các trường hợp nhận thức
Nếu cả hai đối tượng so sánh đều biết và có cùng thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4, thì thuộc tính chung
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 sẽ bị bỏ qua và thời gian cơ sở được so sánh. Nếu cả hai bộ so sánh đều nhận biết và có các thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 khác nhau, thì các bộ so sánh trước tiên được điều chỉnh bằng cách trừ đi độ lệch UTC của chúng [thu được từ
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False30]. Để ngăn các so sánh kiểu hỗn hợp quay trở lại so sánh mặc định theo địa chỉ đối tượng, khi một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 được so sánh với một đối tượng thuộc loại khác,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'481 được nâng lên trừ khi phép so sánh là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'475 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'476. Các trường hợp sau lần lượt trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'247 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'248
Đã thay đổi trong phiên bản 3. 3. Equality comparisons between aware and naive
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 instances don’t raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'481.
Trong ngữ cảnh Boolean, đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 luôn được coi là đúng
Đã thay đổi trong phiên bản 3. 5. Trước Python 3. 5, một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 được coi là sai nếu nó đại diện cho nửa đêm theo giờ UTC. This behavior was considered obscure and error-prone and has been removed in Python 3. 5. Xem bpo-13936 để biết chi tiết đầy đủ.
nhà xây dựng khác
classmethod time. fromisoformat[time_string] ¶Return a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 corresponding to a time_string in any valid ISO 8601 format, with the following exceptions
Time zone offsets may have fractional seconds
The leading
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
1780, normally required in cases where there may be ambiguity between a date and a time, is not requiredPhân số giây có thể có bất kỳ số lượng chữ số nào [bất kỳ số nào vượt quá 6 sẽ bị cắt ngắn]
Fractional hours and minutes are not supported
Examples
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'175
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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'343.
Phương thức sơ thẩm
thời gian. thay thế[giờ=chính mình. giờ , phút=chính mình. phút , giây=chính mình. giây , micro giây=chính mình. micro giây , tzinfo=self. tzinfo , * , gấp=0]¶Trả về một
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 có cùng giá trị, ngoại trừ những thuộc tính được cung cấp giá trị mới theo bất kỳ đối số từ khóa nào được chỉ định. Lưu ý rằng có thể chỉ định
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False52 để tạo một
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 ngây thơ từ một
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 nhận thức mà không cần chuyển đổi dữ liệu thời gian
New in version 3. 6. Added the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'296 argument. time. isoformat[timespec='auto'] ¶
Trả về một chuỗi biểu thị thời gian ở định dạng ISO 8601, một trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
80, if>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 is not 0>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
76, nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 là 0>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
353, nếu>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
57 không trả về>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
356, nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 là 0 và>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
57 không trả về>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403
Đối số tùy chọn timespec chỉ định số lượng thành phần bổ sung của thời gian cần đưa vào [mặc định là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'60]. It can be one of the following
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
60. Giống như>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
62 nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
17 là 0, giống như>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
64 nếu không>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
65. Bao gồm>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14 ở định dạng hai chữ số>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
67>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
68. Bao gồm>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
15 ở định dạng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
71>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
62. Include>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
14,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
15, and>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
16 in>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
76 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
77. Bao gồm toàn thời gian, nhưng cắt ngắn phần thứ hai thành mili giây.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
78 format>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
64. Bao gồm toàn thời gian ở định dạng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
80
Note
Excluded time components are truncated, not rounded
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 sẽ được nâng lên trên một đối số timespec không hợp lệ
Thí dụ
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'176
Mới trong phiên bản 3. 6. Đã thêm đối số thông số thời gian.
thời gian. __str__[] ¶Trong thời gian t,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'455 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'383thời gian. thời gian strf[định dạng] ¶
Trả về một chuỗi biểu thị thời gian, được kiểm soát bởi một chuỗi định dạng rõ ràng. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime[] và strptime[] Hành vi .
thời gian. __format__[định dạng] ¶Giống như
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'384. Điều này cho phép chỉ định một chuỗi định dạng cho một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 trong các chuỗi ký tự được định dạng và khi sử dụng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'274. Để biết danh sách đầy đủ các lệnh định dạng, hãy xem strftime[] và strptime[] Hành vi . thời gian. utcoffset[] ¶
Nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, ngược lại trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'390 và đưa ra một ngoại lệ nếu cái sau không trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 hoặc một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 có cường độ nhỏ hơn một ngày
Đã thay đổi trong phiên bản 3. 7. The UTC offset is not restricted to a whole number of minutes.
thời gian. dst[] ¶Nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, ngược lại trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'396 và đưa ra một ngoại lệ nếu cái sau không trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 hoặc một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 có cường độ nhỏ hơn một ngày
Changed in version 3. 7. The DST offset is not restricted to a whole number of minutes.
time. tzname[] ¶Nếu
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, nếu không thì trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'102 hoặc đưa ra một ngoại lệ nếu cái sau không trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 hoặc một đối tượng chuỗi
Examples of Usage. >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0¶
Ví dụ làm việc với đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'177
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 Đối tượng¶
lớp ngày giờ. tzinfo ¶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 "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 để nắm bắt thông tin về một múi giờ cụ thể
An instance of [a concrete subclass of]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 can be passed to the constructors for
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects. Các đối tượng thứ hai xem các thuộc tính của chúng là theo giờ địa phương và đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 hỗ trợ các phương thức tiết lộ phần bù giờ địa phương từ UTC, tên của múi giờ và phần bù DST, tất cả đều liên quan đến đối tượng ngày hoặc giờ được truyền cho chúng
Bạn cần lấy được một phân lớp cụ thể và [ít nhất] cung cấp các triển khai của các phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 tiêu chuẩn cần thiết cho các phương thức
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 mà bạn sử dụng. Mô-đun
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 cung cấp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8, một phân lớp cụ thể đơn giản của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 có thể biểu thị các múi giờ có phần bù cố định từ UTC, chẳng hạn như chính UTC hoặc EST và EDT của Bắc Mỹ
Yêu cầu đặc biệt đối với dưa chua. Một lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 phải có một phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'118 có thể được gọi mà không có đối số, nếu không, nó có thể được chọn nhưng có thể không được giải nén lại. Đây là yêu cầu kỹ thuật có thể được nới lỏng trong tương lai
Một phân lớp cụ thể của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 có thể cần triển khai các phương pháp sau. Chính xác những phương pháp nào là cần thiết phụ thuộc vào việc sử dụng các đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 nhận thức. Nếu nghi ngờ, chỉ cần thực hiện tất cả chúngtzinfo. utcoffset[dt] ¶
Return offset of local time from UTC, as a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 object that is positive east of UTC. Nếu giờ địa phương ở phía tây của UTC, điều này sẽ là âm
Điều này thể hiện tổng phần bù từ UTC; . Nếu không biết phần bù UTC, hãy trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403. Mặt khác, giá trị được trả về phải là một đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 nằm trong khoảng từ
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'126 đến
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'127 [độ lớn của phần bù phải nhỏ hơn một ngày]. Most implementations of
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 will probably look like one of these two
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'178
Nếu
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 không trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, thì
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 cũng không nên trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403
Việc thực hiện mặc định của
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'134
Đã thay đổi trong phiên bản 3. 7. The UTC offset is not restricted to a whole number of minutes.
tzinfo. dst[dt] ¶Trả về điều chỉnh thời gian tiết kiệm ánh sáng ban ngày [DST], dưới dạng đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 nếu không biết thông tin DST
Trả lại
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'483 nếu DST không có hiệu lực. If DST is in effect, return the offset as a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 object [see
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False57 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 False57, 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 False58 unless you’re interested in obtaining DST info separately. Ví dụ:
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'25 gọi phương thức
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 của thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 để xác định cách đặt cờ
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False97 và
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False70 gọi
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 để giải thích cho các thay đổi DST khi vượt qua các múi giờ
Ví dụ tz của lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 mô hình hóa cả thời gian tiêu chuẩn và thời gian ban ngày phải nhất quán theo nghĩa này
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'149
phải trả về cùng một kết quả cho mỗi
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 dt với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'151 Đối với các lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 lành mạnh, biểu thức này mang lại "độ lệch chuẩn" của múi giờ, không phụ thuộc vào ngày hoặc giờ mà chỉ phụ thuộc vào vị trí địa lý. Việc triển khai
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'153 dựa vào điều này, nhưng không thể phát hiện vi phạm; . If a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass cannot guarantee this, it may be able to override the default implementation of
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False70 to work correctly with
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 regardless
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 False58 có thể sẽ giống như một trong hai
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'179
or
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False0
The default implementation of
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False58 raises
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'134
Changed in version 3. 7. The DST offset is not restricted to a whole number of minutes.
tzinfo. tzname[dt] ¶Trả về tên múi giờ tương ứng với đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 dt, dưới dạng chuỗi. Không có gì về tên chuỗi được xác định bởi mô-đun
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 và không có yêu cầu rằng nó có ý nghĩa cụ thể. Ví dụ: “GMT”, “UTC”, “-500”, “-5. 00”, “EDT”, “US/Eastern”, “America/New York” đều là những câu trả lời hợp lệ. Trả lại
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 nếu không biết tên chuỗi. Lưu ý rằng đây chủ yếu là một phương thức chứ không phải là một chuỗi cố định vì một số lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 sẽ muốn trả về các tên khác nhau tùy thuộc vào giá trị cụ thể của dt được truyền, đặc biệt nếu lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 chiếm thời gian ban ngày
Việc thực hiện mặc định của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'165 tăng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'134
Các phương thức này được gọi bởi một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 hoặc
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0, để đáp lại các phương thức cùng tên của chúng. Đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 chuyển chính nó làm đối số và đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 chuyển
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 làm đối số. A
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclass’s methods should therefore be prepared to accept a dt argument of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403, or of class
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7
Khi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 được thông qua, người thiết kế lớp sẽ quyết định phản hồi tốt nhất. Ví dụ: trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403 là phù hợp nếu lớp muốn nói rằng các đối tượng thời gian không tham gia vào các giao thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4. Có thể hữu ích hơn khi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'178 trả về phần bù UTC tiêu chuẩn, vì không có quy ước nào khác để khám phá phần bù tiêu chuẩn
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 False7 được truyền để phản hồi một phương thức
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'181 chính là đối tượng như self. Các phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 có thể dựa vào điều này, trừ khi mã người dùng gọi trực tiếp các phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4. Mục đích là các phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 diễn giải dt theo giờ địa phương và không cần lo lắng về các đối tượng ở các múi giờ khác
Có thêm một phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 mà một lớp con có thể muốn ghi đètzinfo. từutc[dt] ¶
Điều này được gọi từ triển khai
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'153 mặc định. Khi được gọi từ đó,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'181 là chính nó và dữ liệu ngày và giờ của dt sẽ được xem là thể hiện thời gian UTC. The purpose of
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'188 is to adjust the date and time data, returning an equivalent datetime in self’s local time
Most
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 subclasses should be able to inherit the default
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'188 implementation without problems. Nó đủ mạnh để xử lý các múi giờ có độ lệch cố định và các múi giờ chiếm cả thời gian tiêu chuẩn và thời gian ban ngày và cả thời gian sau ngay cả khi thời gian chuyển đổi DST khác nhau trong các năm khác nhau. Một ví dụ về múi giờ mà việc triển khai
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'188 mặc định có thể không xử lý chính xác trong mọi trường hợp là trường hợp mà phần bù tiêu chuẩn [từ UTC] phụ thuộc vào ngày và giờ cụ thể đã trôi qua, điều này có thể xảy ra vì lý do chính trị. The default implementations of
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'188 may not produce the result you want if the result is one of the hours straddling the moment the standard offset changes
Bỏ qua mã cho các trường hợp lỗi, việc triển khai
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'188 mặc định hoạt động như
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False1
Trong tệp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'195 sau đây có một số ví dụ về lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False2
Lưu ý rằng có những sự tinh tế không thể tránh khỏi hai lần mỗi năm trong phân lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 cho cả thời gian tiêu chuẩn và thời gian ban ngày, tại các điểm chuyển tiếp DST. Để cụ thể, hãy xem xét Miền Đông Hoa Kỳ [UTC -0500], nơi EDT bắt đầu sau 1 phút. 59 [EST] vào Chủ nhật thứ hai của tháng 3 và kết thúc vào phút sau 1. 59 [EDT] 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 False3
Khi DST bắt đầu [dòng “bắt đầu”], đồng hồ treo tường địa phương nhảy từ 1. 59 đến 3. 00. Một bức tường thời gian của mẫu 2. MM không thực sự có ý nghĩa vào ngày đó, vì vậy
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'198 sẽ không mang lại kết quả với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'199 vào ngày DST bắt đầu. Ví dụ: tại chuyển tiếp mùa xuân năm 2016, chúng tôi nhận được
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False4
Khi DST kết thúc [dòng “kết thúc”], có khả năng xảy ra sự cố tồi tệ hơn. there’s an hour that can’t be spelled unambiguously in local wall time. giờ cuối cùng của thời gian ban ngày. Ở phương Đông, đó là thời gian của mẫu 5. MM UTC on the day daylight time ends. Đồng hồ treo tường địa phương nhảy từ 1. 59 [thời gian ban ngày] trở lại 1. 00 [giờ chuẩn] lại. Local times of the form 1. MM không rõ ràng.
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False72 bắt chước hành vi của đồng hồ địa phương bằng cách ánh xạ hai giờ UTC liền kề vào cùng một giờ địa phương sau đó. Trong ví dụ phương Đông, thời gian UTC có dạng 5. MM và 6. MM cả ánh xạ tới 1. MM khi được chuyển đổi thành Eastern, nhưng những lần trước đó thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'296 được đặt thành 0 và những lần sau thuộc tính này được đặt thành 1. Ví dụ: tại Fall back transition năm 2016, chúng tôi nhận được
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False5
Lưu ý rằng các trường hợp
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 chỉ khác nhau về giá trị của thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'296 được coi là bằng nhau khi so sánh
Các ứng dụng không thể chịu được sự mơ hồ về thời gian treo tường nên kiểm tra rõ ràng giá trị của thuộc tính
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'296 hoặc tránh sử dụng các lớp con
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 kết hợp;
Xem thêm
Cơ sở dữ liệu múi giờ IANA>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1Mô-đun
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 có lớp>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 cơ bản [để xử lý các giá trị bù trừ cố định tùy ý từ UTC] và thuộc tính>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7111 của nó [một thể hiện múi giờ UTC]>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'1 brings the IANA timezone database [also known as the Olson database] to Python, and its usage is recommended
The Time Zone Database [often called tz, tzdata or zoneinfo] contains code and data that represent the history of local time for many representative locations around the globe. Nó được cập nhật định kỳ để phản ánh những thay đổi do các cơ quan chính trị thực hiện đối với ranh giới múi giờ, độ lệch UTC và quy tắc tiết kiệm ánh sáng ban ngày
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8 Đối tượng¶
Lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 là một lớp con của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4, mỗi phiên bản đại diện cho một múi giờ được xác định bởi phần bù cố định từ UTC
Các đối tượng của lớp này không thể được sử dụng để biểu thị thông tin múi giờ ở những vị trí sử dụng các độ lệch khác nhau trong các ngày khác nhau trong năm hoặc khi các thay đổi lịch sử đã được thực hiện đối với thời gian dân sự
class datetime. múi giờ[độ lệch , tên=None]¶The offset argument must be specified as a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 object representing the difference between the local time and UTC. Nó phải hoàn toàn nằm giữa
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'126 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'127, nếu không thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'493 được nâng lên
Đối số tên là tùy chọn. Nếu được chỉ định, nó phải là một chuỗi sẽ được sử dụng làm giá trị được trả về bởi phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7120
Mới trong phiên bản 3. 2
Đã thay đổi trong phiên bản 3. 7. The UTC offset is not restricted to a whole number of minutes.
timezone. utcoffset[dt] ¶Trả về giá trị cố định được chỉ định khi phiên bản
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 được tạo
The dt argument is ignored. The return value is a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'411 instance equal to the difference between the local time and UTC
Đã thay đổi trong phiên bản 3. 7. The UTC offset is not restricted to a whole number of minutes.
timezone. tzname[dt] ¶Trả về giá trị cố định được chỉ định khi phiên bản
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'8 được tạo
If name is not provided in the constructor, the name returned by
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7124 is generated from the value of the
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7125 as follows. Nếu offset là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'483, tên là “UTC”, nếu không, nó là một chuỗi ở định dạng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7127, trong đó ± là dấu của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7125, HH và MM lần lượt là hai chữ số của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7129 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7130
Đã thay đổi trong phiên bản 3. 6. Tên được tạo từ
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7131 hiện là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7132 đơn giản, không phải
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7133. timezone. dst[dt] ¶
Luôn trả về
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'403múi giờ. từutc[dt] ¶
Return
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7135. The dt argument must be an aware
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 instance, with
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'4 set to
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7138
Thuộc tính lớp
múi giờ. utc ¶Múi giờ UTC,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7139
>>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7140 và >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141 Hành vi¶
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32,
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7, and
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 objects all support a
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7145 method, to create a string representing the time under the control of an explicit format string
Ngược lại, phương thức của lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7146 tạo một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 từ một chuỗi biểu thị ngày giờ và một chuỗi định dạng tương ứng
Bảng dưới đây cung cấp so sánh cấp cao giữa
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7140 so với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7141
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7150
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7151
Cách sử dụng
Convert object to a string according to a given format
Phân tích một chuỗi thành một đối tượng
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7 với định dạng tương ứng
Loại phương pháp
Instance method
phương pháp lớp
Phương pháp của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32;
>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False7
Chữ ký
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7145
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7158
Mã định dạng >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7140 và >>> delta2 > delta1
True
>>> delta2 > 5
Traceback [most recent call last]:
File "", line 1, in
TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141¶
Sau đây là danh sách tất cả các mã định dạng mà tiêu chuẩn C 1989 yêu cầu và chúng hoạt động trên tất cả các nền tảng có triển khai C tiêu chuẩn
Directive
Meaning
Example
ghi chú
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7161
Weekday as locale’s abbreviated name
Sun, Mon, …, Sat [en_US];
So, Mo, …, Sa [de_DE]
[1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7162
Ngày trong tuần là tên đầy đủ của ngôn ngữ
Chủ Nhật, Thứ Hai, …, Thứ Bảy [en_US];
Sonntag, Montag, …, Samstag [de_DE]
[1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7163
Weekday as a decimal number, where 0 is Sunday and 6 is Saturday
0, 1, …, 6
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7164
Ngày trong tháng dưới dạng số thập phân không đệm
01, 02, …, 31
[9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7165
Tháng là tên viết tắt của ngôn ngữ
Jan, Feb, …, Dec [en_US];
Jan, Feb, …, Dez [de_DE]
[1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7166
Tháng là tên đầy đủ của ngôn ngữ
Tháng Giêng, Tháng Hai, …, Tháng Mười Hai [en_US];
Januar, Februar, …, Dezember [de_DE]
[1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7167
Tháng dưới dạng số thập phân không đệm
01, 02, …, 12
[9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7168
Year without century as a zero-padded decimal number
00, 01, …, 99
[9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7169
Năm với thế kỷ dưới dạng số thập phân
0001, 0002, …, 2013, 2014, …, 9998, 9999
[2]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7170
Giờ [đồng hồ 24 giờ] dưới dạng số thập phân không đệm
00, 01, …, 23
[9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7171
Giờ [đồng hồ 12 giờ] dưới dạng số thập phân không đệm
01, 02, …, 12
[9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7172
Locale’s equivalent of either AM or PM
AM, PM [en_US];
sáng, chiều [de_DE]
[1], [3]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7173
Phút dưới dạng số thập phân không đệm
00, 01, …, 59
[9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7174
Thứ hai dưới dạng số thập phân không đệm
00, 01, …, 59
[4], [9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7175
Microsecond as a decimal number, zero-padded to 6 digits
000000, 000001, …, 999999
[5]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7176
Phần bù UTC ở dạng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7177 [chuỗi trống nếu đối tượng là ngây thơ]
[empty], +0000, -0400, +1030, +063415, -030712. 345216
[6]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7178
Tên múi giờ [chuỗi trống nếu đối tượng ngây thơ]
[trống], UTC, GMT
[6]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7179
Day of the year as a zero-padded decimal number
001, 002, …, 366
[9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7180
Week number of the year [Sunday as the first day of the week] as a zero-padded decimal number. All days in a new year preceding the first Sunday are considered to be in week 0
00, 01, …, 53
[7], [9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7181
Số tuần của năm [Thứ Hai là ngày đầu tiên của tuần] dưới dạng số thập phân không đệm. Tất cả các ngày trong năm mới trước ngày thứ Hai đầu tiên được coi là trong tuần 0
00, 01, …, 53
[7], [9]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7182
Đại diện ngày và giờ thích hợp của ngôn ngữ
Thứ ba 16 tháng 8 21. 30. 00 1988 [vi_Hoa Kỳ];
Di 16 Thg8 21. 30. 00 1988 [de_DE]
[1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7183
Đại diện ngày thích hợp của địa phương
16/08/88 [Không có];
16/08/1988 [en_US];
16. 08. 1988 [de_DE]
[1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7184
Đại diện thời gian thích hợp của địa phương
21. 30. 00 [vi_US];
21. 30. 00 [de_DE]
[1]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7185
Một ký tự
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7186 theo nghĩa đen
%
Một số chỉ thị bổ sung không bắt buộc theo tiêu chuẩn C89 được bao gồm để thuận tiện. Tất cả các tham số này đều tương ứng với các giá trị ngày theo tiêu chuẩn ISO 8601
Directive
Meaning
Example
ghi chú
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7187
Năm ISO 8601 với thế kỷ đại diện cho năm chứa phần lớn tuần ISO [
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7188]
0001, 0002, …, 2013, 2014, …, 9998, 9999
[số 8]
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7189
ISO 8601 weekday as a decimal number where 1 is Monday
1, 2, …, 7
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7188
ISO 8601 tuần dưới dạng số thập phân với Thứ Hai là ngày đầu tuần. Tuần 01 là tuần có ngày 04/01
01, 02, …, 53
[8], [9]
Những thứ này có thể không khả dụng trên tất cả các nền tảng khi được sử dụng với phương pháp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7140. Chỉ thị năm và tuần ISO 8601 không thể hoán đổi cho nhau với chỉ thị số năm và tuần ở trên. Gọi _____17141 với các chỉ thị ISO 8601 không đầy đủ hoặc mơ hồ sẽ tăng ____5493
Bộ mã định dạng đầy đủ được hỗ trợ khác nhau giữa các nền tảng, bởi vì Python gọi hàm
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7140 của thư viện C và các biến thể nền tảng là phổ biến. Để xem toàn bộ mã định dạng được hỗ trợ trên nền tảng của bạn, hãy tham khảo tài liệu strftime[3]. Cũng có sự khác biệt giữa các nền tảng trong việc xử lý các thông số định dạng không được hỗ trợ
Mới trong phiên bản 3. 6. ______17187,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7189 và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7188 đã được thêm vào.
Chi tiết kỹ thuật¶
Nói chung,
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7198 hoạt động giống như mô-đun
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'900 của
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 mặc dù không phải tất cả các đối tượng đều hỗ trợ phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'242
Đối với phương thức lớp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7146, giá trị mặc định là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'903. any components not specified in the format string will be pulled from the default value. 4
Sử dụng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'904 tương đương với
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'21
ngoại trừ khi định dạng bao gồm các thành phần giây phụ hoặc thông tin bù múi giờ, được hỗ trợ trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'905 nhưng bị loại bỏ bởi
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'906
Đối với đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0, không nên sử dụng mã định dạng cho năm, tháng và ngày vì đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'0 không có giá trị như vậy. Nếu chúng vẫn được sử dụng, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'909 được thay thế cho năm và
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'35 cho tháng và ngày
Đối với đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32, không nên sử dụng mã định dạng cho giờ, phút, giây và micro giây vì đối tượng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'32 không có các giá trị như vậy. Nếu chúng vẫn được sử dụng, thì
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'414 sẽ được thay thế cho chúng
Vì lý do tương tự, việc xử lý các chuỗi định dạng chứa các điểm mã Unicode không thể được biểu thị trong bộ ký tự của ngôn ngữ hiện tại cũng phụ thuộc vào nền tảng. On some platforms such code points are preserved intact in the output, while on others
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'7150 may raise
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'915 or return an empty string instead
ghi chú
Vì định dạng phụ thuộc vào ngôn ngữ hiện tại nên cần cẩn thận khi đưa ra các giả định về giá trị đầu ra. Thứ tự trường sẽ khác nhau [ví dụ: “tháng/ngày/năm” so với “ngày/tháng/năm”] và đầu ra có thể chứa các ký tự Unicode được mã hóa bằng mã hóa mặc định của ngôn ngữ [ví dụ: nếu ngôn ngữ hiện tại là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
916,Phương pháp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141 có thể phân tích các năm trong phạm vi [1, 9999] đầy đủ, nhưng các năm < 1000 phải được điền bằng 0 để có chiều rộng 4 chữ sốChanged in version 3. 2. Trong các phiên bản trước, phương pháp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7140 bị giới hạn trong các năm >= 1900.Đã thay đổi trong phiên bản 3. 3. In version 3. 2, phương pháp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7140 bị giới hạn trong các năm >= 1000.Khi được sử dụng với phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141, lệnh>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7172 chỉ ảnh hưởng đến trường giờ đầu ra nếu lệnh>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7171 được sử dụng để phân tích cú pháp giờKhông giống như mô-đun
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
0, mô-đun>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 không hỗ trợ giây nhuậnKhi được sử dụng với phương thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141, chỉ thị>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7175 chấp nhận từ một đến sáu chữ số và số không ở bên phải.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7175 là một phần mở rộng cho tập hợp các ký tự định dạng trong tiêu chuẩn C [nhưng được triển khai riêng trong các đối tượng ngày giờ và do đó luôn có sẵn]Đối với một đối tượng ngây thơ, mã định dạng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7176 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7178 được thay thế bằng các chuỗi rỗngĐối với một đối tượng nhận thức
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7176>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
57 được chuyển đổi thành một chuỗi có dạng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7177, trong đó>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
67 là chuỗi 2 chữ số cho biết số giờ bù UTC,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
938 là chuỗi 2 chữ số cho số phút bù UTC,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
939 là chuỗi 2 chữ số cho . Phần>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
940 bị bỏ qua khi phần bù là một số nguyên giây và cả phần>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
940 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
939 đều bị bỏ qua khi phần bù là một số nguyên phút. Ví dụ: nếu>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
57 trả về>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
945, thì>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7176 được thay thế bằng chuỗi>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
947Đã thay đổi trong phiên bản 3. 7. The UTC offset is not restricted to a whole number of minutes.
Đã thay đổi trong phiên bản 3. 7. Khi chỉ thị
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7176 được cung cấp cho phương pháp>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141, phần bù UTC có thể có dấu hai chấm làm dấu phân cách giữa giờ, phút và giây. Ví dụ:>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
950 sẽ được phân tích thành phần bù của một giờ. Ngoài ra, cung cấp>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
951 giống với>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
952.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7178Trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7140,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7178 được thay thế bằng một chuỗi rỗng nếu>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
165 trả về>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
403;>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141 chỉ chấp nhận các giá trị nhất định cho>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7178bất kỳ giá trị nào trong
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
961 cho ngôn ngữ máy của bạncác giá trị mã hóa cứng
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
962 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
963
Vì vậy, ai đó sống ở Nhật Bản có thể có giá trị hợp lệ là
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
964,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
962 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
963, nhưng có thể không phải là>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
967. Nó sẽ tăng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
493 cho các giá trị không hợp lệĐã thay đổi trong phiên bản 3. 2. Khi chỉ thị
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7176 được cung cấp cho phương thức>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141, một đối tượng>>> from datetime import timedelta >>> delta1 = timedelta[seconds=57] >>> delta2 = timedelta[hours=25, seconds=2] >>> delta2 != delta1 True >>> delta2 == 5 False
7 nhận biết sẽ được tạo ra.>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
4 của kết quả sẽ được đặt thành phiên bản>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
8.Khi được sử dụng với phương pháp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7180 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7181 chỉ được sử dụng trong các phép tính khi ngày trong tuần và năm dương lịch [>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7169] được chỉ địnhTương tự như
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7180 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7181,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7188 chỉ được sử dụng trong tính toán khi ngày trong tuần và năm ISO [>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7187] được chỉ định trong chuỗi định dạng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141. Cũng lưu ý rằng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7187 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7169 không thể hoán đổi cho nhauKhi được sử dụng với phương pháp
>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7141, số 0 đứng đầu là tùy chọn đối với các định dạng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7164,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7167,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7170,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7171,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7173,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7174,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7179,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7180,>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7181 và>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7188. Định dạng>>> delta2 > delta1 True >>> delta2 > 5 Traceback [most recent call last]: File "", line 1, in TypeError: '>' not supported between instances of 'datetime.timedelta' and 'int'
7168 không yêu cầu số 0 đứng đầu
chú thích
1Nghĩa là, nếu chúng ta bỏ qua các tác động của Thuyết tương đối
2Điều này phù hợp với định nghĩa của lịch “proleptic Gregorian” trong cuốn sách Tính toán Lịch của Dershowitz và Reingold, trong đó nó là lịch cơ sở cho tất cả các phép tính. Xem sách để biết các thuật toán chuyển đổi giữa các thứ tự Gregorian proleptic và nhiều hệ thống lịch khác