6-misol: Vaqtni ifodalash uchun vaqt ob'ekti
from datetime import time
# time(hour = 0, minute = 0, second = 0)
a = time()
print(a)
# time(hour, minute and second)
b = time(11, 34, 56)
print(b)
# time(hour, minute and second)
c = time(hour = 11, minute = 34, second = 56)
print(c)
# time(hour, minute, second, microsecond)
d = time(11, 34, 56, 234566)
print(d)
Chiqish_a_=_00:00:00_b_=_11:34:56_c_=_11:34:56_d_=_11:34:56.234566_7-misol:_Soat,_daqiqa,_soniya_va_mikrosoniyani_chop_etish'>Chiqish
a = 00:00:00
b = 11:34:56
c = 11:34:56
d = 11:34:56.234566
7-misol: Soat, daqiqa, soniya va mikrosoniyani chop etish
Ob'ektni yaratganimizdan so'ng time sinfi orqali biz uning atributlarini osongina chop etishimiz mumkin, masalan hour, minute va hokazo. Masalan,
from datetime import time
a = time(11, 34, 56)
print("Hour =", a.hour)
print("Minute =", a.minute)
print("Second =", a.second)
print("Microsecond =", a.microsecond)
Chiqish
Hour = 11
Minute = 34
Second = 56
Microsecond = 0
1.3 Python datetime.datetime sinfi
Modulda sana va vaqt ob'ektlaridan ma'lumotlarni o'z ichiga olishi mumkin bo'lgan datetime nomli sinf mavjud.
8-misol: Python datetime obyekti
from datetime import datetime
# datetime(year, month, day)
a = datetime(2022, 12, 28)
print(a)
# datetime(year, month, day, hour, minute, second, microsecond)
b = datetime(2022, 12, 28, 23, 55, 59, 342380)
print(b)
Chiqish
2022-12-28 00:00:00
2022-12-28 23:55:59.342380
Birinchi uchtalik yil, oy, kun datetime modulida asosiy hisoblanadi.
Do'stlaringiz bilan baham: |