Hướng dẫn how do i print minutes and seconds in python? - làm cách nào để in phút và giây trong python?
Đây là cách tôi có được nó. Show
Vài ví dụ: Cải thiện bài viết Lưu bài viết Cải thiện bài viết Lưu bài viết ĐọcExamples: Input : 12345 Output : 3:25:45 Input : 3600 Output : 1:00:00 Bàn luậnNaive This approach is simply a naive approach to get the hours, minutes and seconds by simple mathematical calculations. Python3
Cho một số nguyên n (tính bằng giây), chuyển đổi thành giờ, phút và giây. Ví dụ: Cách tiếp cận số 1: Naive Cách tiếp cận này chỉ đơn giản là một cách tiếp cận ngây thơ để có được giờ, phút và giây bằng các tính toán toán học đơn giản. & NBSP;
6= seconds 9 9 3
3
Input : 12345 Output : 3:25:45 Input : 3600 Output : 1:00:008 = seconds 9 9 def 3
Độ phức tạp về thời gian: O (1) Không gian phụ trợ: O (1)O(1) Cải thiện bài viếtApproach #2 : Alternate to the Naive approach By using the divmod() function, which does only a single division to produce both the quotient and the remainder, you can have the result very quickly with only two mathematical operations. Python3
Lưu bài viết Đọc Bàn luận
Độ phức tạp về thời gian: O (1) Không gian phụ trợ: O (1)O(1) Cải thiện bài viếtApproach #3 : Using timedelta (Object of datetime module) Datetime module provides timedelta object which represents a duration, the difference between two dates or times. datetime.timedelta can be used to represent seconds into hours, minutes and seconds format. Python3Lưu bài viết Đọc Bàn luận
Độ phức tạp về thời gian: O (1) Không gian phụ trợ: O (1)O(1) Cải thiện bài viếtApproach #4 : Using time.strftime() time.strftime() gives more control over formatting. The format and time.gmtime() is passed as argument. gmtime is used to convert seconds to special tuple format that strftime() requires. Python3
022____103 04
Độ phức tạp về thời gian: O (1) Không gian phụ trợ: O (1)O(1) |