Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4e43193

Browse files
committed
Add more to pytz example
1 parent ebd1b94 commit 4e43193

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

books/pc/ch3/ch3_16_2.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
from pytz import timezone
44

55
if __name__ == "__main__":
6+
print(datetime.utcnow())
7+
68
d = datetime(2012, 12, 12, 9, 30, 0)
79
print(d)
810

@@ -33,3 +35,18 @@
3335

3436
beijing_time = new_york_time.astimezone(timezone("Asia/Shanghai"))
3537
print(beijing_time)
38+
39+
print("More")
40+
utc_tz_name = "UTC"
41+
pdt_tz_name = "America/Los_Angeles"
42+
43+
utc_tz = timezone(utc_tz_name)
44+
pdt_tz = timezone(pdt_tz_name)
45+
46+
_utc_now = datetime.utcnow()
47+
_utc_now = utc_tz.localize(_utc_now)
48+
49+
pdt_now = _utc_now.astimezone(pdt_tz)
50+
print(_utc_now)
51+
print(pdt_now)
52+
print(pdt_now.strftime("%Y-%m-%d"))

0 commit comments

Comments
 (0)