• Chiqish Hour = 11 Minute = 34 Second = 56 Microsecond = 0 1.3 Python datetime.datetime sinfi Modulda sana va vaqt
  • 9-misol: Yil, oy, soat, daqiqa va sekundni chop etish
  • Chiqish Year = 2022 Month = 12 Day = 28 Hour = 23 Minute = 55 Timestamp = 1511913359.34238 2.Python datetime.strftime()
  • Python dasturlash tilida sana va vaqt bilan ishlash modullari




    Download 24,96 Kb.
    bet4/7
    Sana05.01.2024
    Hajmi24,96 Kb.
    #130768
    1   2   3   4   5   6   7
    Bog'liq
    Python dasturlash tilida sana va vaqt bilan ishlash modullari-fayllar.org (1)

    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.
    9-misol: Yil, oy, soat, daqiqa va sekundni chop etish
    from datetime import datetime

    a = datetime(2022, 12, 28, 23, 55, 59, 342380)


    print("Year =", a.year)


    print("Month =", a.month)
    print("Day =", a.day)
    print("Hour =", a.hour)
    print("Minute =", a.minute)
    print("Timestamp =", a.timestamp())
    Chiqish
    Year = 2022
    Month = 12
    Day = 28
    Hour = 23
    Minute = 55
    Timestamp = 1511913359.34238

    2.Python datetime.strftime()
    date , time yoki datetime obyektini strftime() yordamida sana va vaqtni ifodalovchi qatorni qaytaradi .

    Download 24,96 Kb.
    1   2   3   4   5   6   7




    Download 24,96 Kb.

    Bosh sahifa
    Aloqalar

        Bosh sahifa



    Python dasturlash tilida sana va vaqt bilan ishlash modullari

    Download 24,96 Kb.