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.
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:
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 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 |
댓글 영역