Python_40_ datetime

hyeong taek jo·2023년 9월 15일

Python

목록 보기
44/53

📌 datetime

  • from datetime import date 이런식으로 쓰던가
  • import datetime 이렇게 사용해도 된다.
from datetime import date
from datetime import time

def calc_date(yy, mm, dd):
    # date Create
    c_date = date(yy, mm, dd)
    return c_date

def calc_time(hr, mi, sc):
    # time Create
    c_time = time(hr, mi, sc)
    return c_time

def main():
    # date
    yy = 2019
    mm = 8
    dd = 20
    #time
    hr = 22
    mi = 50
    sc = 57
    # Date 계산
    rDate = calc_date(yy, mm, dd)
    print('rDate-> {}'.format(rDate))
    print('rDate.month-> {}'.format(rDate.month))
    print('rDate.day-> {}' .format(rDate.day))
    print('rDate.day-> {}' .format(rDate.day))
    print('rDate.year-> {}' .format(rDate.year))

    rTime = calc_time(hr, mi, sc)
    print('rTime-> {}'.format(rTime))
    print('rTime.hour-> {}'.format(rTime.hour))
    print('rTime.minute-> {}'.format(rTime.minute))
    print('rTime.second-> {}'.format(rTime.second))

if __name__ == '__main__':
    main()

rDate-> 2019-08-20
rDate.month-> 8
rDate.day-> 20
rDate.day-> 20
rDate.year-> 2019
rTime-> 22:50:57
rTime.hour-> 22
rTime.minute-> 50
rTime.second-> 57

profile
마포구 주민

0개의 댓글