Skip to content

Commit f6d0c49

Browse files
committed
datetime
1 parent b9d5e59 commit f6d0c49

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

16_Day_Python_date_time/16_python_datetime.md

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99

1010
<sub>Author:
1111
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
12-
<small> First Edition: Nov 22 - Dec 22, 2019</small>
12+
<small>Second Edition: July, 2021</small>
1313
</sub>
14-
</div>
14+
1515
</div>
1616

1717
[<< Day 15](../15_Day_Python_type_errors/15_python_type_errors.md) | [Day 17 >>](../17_Day_Exception_handling/17_exception_handling.md)
@@ -20,7 +20,7 @@
2020
- [📘 Day 16](#-day-16)
2121
- [Python *datetime*](#python-datetime)
2222
- [Getting *datetime* Information](#getting-datetime-information)
23-
- [Formating Date Output Using *strftime*](#formating-date-output-using-strftime)
23+
- [Formatting Date Output Using *strftime*](#formatting-date-output-using-strftime)
2424
- [String to Time Using *strptime*](#string-to-time-using-strptime)
2525
- [Using *date* from *datetime*](#using-date-from-datetime)
2626
- [Time Objects to Represent Time](#time-objects-to-represent-time)
@@ -39,29 +39,29 @@ print(dir(datetime))
3939
['MAXYEAR', 'MINYEAR', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'date', 'datetime', 'datetime_CAPI', 'sys', 'time', 'timedelta', 'timezone', 'tzinfo']
4040
```
4141

42-
With dir or help built-in commands it is possible to know the available functions in a certain module. As you can see, in the datetime module there are many functions, but we will focus on _date_, _datetime_, _time_ and _timedelta_. Let's see them one by one.
42+
With dir or help built-in commands it is possible to know the available functions in a certain module. As you can see, in the datetime module there are many functions, but we will focus on _date_, _datetime_, _time_ and _timedelta_. Let se see them one by one.
4343

4444
### Getting *datetime* Information
4545

4646
```py
4747
from datetime import datetime
4848
now = datetime.now()
49-
print(now) # 2019-12-04 23:34:46.549883
50-
day = now.day # 4
51-
month = now.month # 12
52-
year = now.year # 2019
53-
hour = now.hour # 23
49+
print(now) # 2021-07-08 07:34:46.549883
50+
day = now.day # 8
51+
month = now.month # 7
52+
year = now.year # 2021
53+
hour = now.hour # 7
5454
minute = now.minute # 38
5555
second = now.second
5656
timestamp = now.timestamp()
5757
print(day, month, year, hour, minute)
5858
print('timestamp', timestamp)
59-
print(f'{day}/{month}/{year}, {hour}:{minute}') # 4/12/2019, 23:38
59+
print(f'{day}/{month}/{year}, {hour}:{minute}') # 8/7/2021, 7:38
6060
```
6161

6262
Timestamp or Unix timestamp is the number of seconds elapsed from 1st of January 1970 UTC.
6363

64-
### Formating Date Output Using *strftime*
64+
### Formatting Date Output Using *strftime*
6565

6666
```py
6767
from datetime import datetime
@@ -78,7 +78,7 @@ print(f'{day}/{month}/{year}, {hour}:{minute}') # 1/1/2020, 0:0
7878

7979
```
8080

81-
Time formating
81+
Formatting date time using *strftime* method and the documentation can be found [here](https://strftime.org/).
8282

8383
```py
8484
from datetime import datetime
@@ -102,9 +102,10 @@ time two: 05/12/2019, 01:05:01
102102

103103
Here are all the _strftime_ symbols we use to format time. An example of all the formats for this module.
104104

105-
![strftime](./images/strftime.png)
105+
![strftime](../images/strftime.png)
106106

107107
### String to Time Using *strptime*
108+
Here is a [documentation](https://www.programiz.com/python-programming/datetime/strptimet) hat helps to understand the format.
108109

109110
```py
110111
from datetime import datetime
@@ -188,7 +189,7 @@ print("t3 =", t3)
188189
t3 = 86 days, 22:56:50
189190
```
190191

191-
🌕 You are extraordinary. You are 16 steps a head to your way to greatness. Now do some exercises for your brain and for your muscle.
192+
🌕 You are an extraordinary. You are 16 steps a head to your way to greatness. Now do some exercises for your brain and muscles.
192193

193194
## 💻 Exercises: Day 16
194195

0 commit comments

Comments
 (0)