mirror of
https://github.com/apachecn/ailearning.git
synced 2026-05-01 22:10:45 +08:00
2020-10-19 21:08:55
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
In [1]:
|
||||
|
||||
```
|
||||
```py
|
||||
import datetime as dt
|
||||
|
||||
```
|
||||
@@ -15,7 +15,7 @@ import datetime as dt
|
||||
|
||||
In [2]:
|
||||
|
||||
```
|
||||
```py
|
||||
d1 = dt.date(2007, 9, 25)
|
||||
d2 = dt.date(2008, 9, 25)
|
||||
|
||||
@@ -25,14 +25,14 @@ d2 = dt.date(2008, 9, 25)
|
||||
|
||||
In [3]:
|
||||
|
||||
```
|
||||
```py
|
||||
print d1
|
||||
print d1.strftime('%A, %m/%d/%y')
|
||||
print d1.strftime('%a, %m-%d-%Y')
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
2007-09-25
|
||||
Tuesday, 09/25/07
|
||||
Tue, 09-25-2007
|
||||
@@ -43,12 +43,12 @@ Tue, 09-25-2007
|
||||
|
||||
In [4]:
|
||||
|
||||
```
|
||||
```py
|
||||
print d2 - d1
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
366 days, 0:00:00
|
||||
|
||||
```
|
||||
@@ -57,14 +57,14 @@ print d2 - d1
|
||||
|
||||
In [5]:
|
||||
|
||||
```
|
||||
```py
|
||||
d = d2 - d1
|
||||
print d.days
|
||||
print d.seconds
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
366
|
||||
0
|
||||
|
||||
@@ -74,12 +74,12 @@ print d.seconds
|
||||
|
||||
In [6]:
|
||||
|
||||
```
|
||||
```py
|
||||
print dt.date.today()
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
2015-09-10
|
||||
|
||||
```
|
||||
@@ -90,7 +90,7 @@ print dt.date.today()
|
||||
|
||||
In [7]:
|
||||
|
||||
```
|
||||
```py
|
||||
t1 = dt.time(15, 38)
|
||||
t2 = dt.time(18)
|
||||
|
||||
@@ -100,14 +100,14 @@ t2 = dt.time(18)
|
||||
|
||||
In [8]:
|
||||
|
||||
```
|
||||
```py
|
||||
print t1
|
||||
print t1.strftime('%I:%M, %p')
|
||||
print t1.strftime('%H:%M:%S, %p')
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
15:38:00
|
||||
03:38, PM
|
||||
15:38:00, PM
|
||||
@@ -124,13 +124,13 @@ print t1.strftime('%H:%M:%S, %p')
|
||||
|
||||
In [9]:
|
||||
|
||||
```
|
||||
```py
|
||||
d1 = dt.datetime.now()
|
||||
print d1
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
2015-09-10 20:58:50.148000
|
||||
|
||||
```
|
||||
@@ -139,13 +139,13 @@ print d1
|
||||
|
||||
In [10]:
|
||||
|
||||
```
|
||||
```py
|
||||
d2 = d1 + dt.timedelta(30)
|
||||
print d2
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
2015-10-10 20:58:50.148000
|
||||
|
||||
```
|
||||
@@ -154,12 +154,12 @@ print d2
|
||||
|
||||
In [11]:
|
||||
|
||||
```
|
||||
```py
|
||||
print dt.datetime.strptime('2/10/01', '%m/%d/%y')
|
||||
|
||||
```
|
||||
|
||||
```
|
||||
```py
|
||||
2001-02-10 00:00:00
|
||||
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user