Autosave: 2024-06-18 08:00:04
This commit is contained in:
parent
85473af3f2
commit
116305d61c
2 changed files with 14 additions and 2 deletions
BIN
.zk/notebook.db
BIN
.zk/notebook.db
Binary file not shown.
|
@ -68,9 +68,21 @@ print("Minute:", some_datetime.minute)
|
||||||
print("Second:", some_datetime.second)
|
print("Second:", some_datetime.second)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Formatting Datetime Objects
|
### Formatting Datetime Objects: `strftime`
|
||||||
|
|
||||||
You can format datetime objects to strings using the `strftime` method.
|
The `strftime` method (_string format time_) converts a datetime object to a
|
||||||
|
string according to the specified format.
|
||||||
|
|
||||||
|
In the example below we use `strftime` to express the current date as YYYY-MM:
|
||||||
|
|
||||||
|
```python
|
||||||
|
now = datetime.now()
|
||||||
|
formatted = now.strftime('%Y-%m')
|
||||||
|
print(formatted)
|
||||||
|
# 2024-06
|
||||||
|
```
|
||||||
|
|
||||||
|
Another example, for YYYY-MM-DD H:M:S:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
formatted_datetime = some_datetime.strftime('%Y-%m-%d %H:%M:%S')
|
formatted_datetime = some_datetime.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
Loading…
Add table
Reference in a new issue