상세 컨텐츠

본문 제목

파이썬 detetime 모듈 개념

파이썬

by somiyuralove 2023. 4. 16. 16:27

본문

Python Dates

A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects.

Date Output

When we execute the code from the example above the result will be:2023-04-16 16:12:06.572136

The date contains year, month, day, hour, minute, second, and microsecond.

The datetime module has many methods to return information about the date object.

Here are a few examples, you will learn more about them later in this chapter:

Creating Date Objects

To create a date, we can use the datetime() class (constructor) of the datetime module.

The datetime() class requires three parameters to create a date: year, month, day.

he datetime() class also takes parameters for time and timezone (hour, minute, second, microsecond, tzone), but they are optional, and has a default value of 0, (None for timezone).

The strftime() Method

The datetime object has a method for formatting date objects into readable strings.

The method is called strftime(), and takes one parameter, format, to specify the format of the returned string:

 

'파이썬' 카테고리의 다른 글

파이썬 클래스 개념  (0) 2023.04.17
파이썬 모듈의 개념  (0) 2023.04.14
파이썬 상속 개념  (0) 2023.04.14
format  (0) 2023.04.12

관련글 더보기

댓글 영역