File tree Expand file tree Collapse file tree 3 files changed +51
-1
lines changed
builtin_packages/datetime_sp Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 1
- import functools
2
1
import base64
2
+ import functools
3
3
import inspect
4
4
5
5
Original file line number Diff line number Diff line change
1
+ import time
2
+ import datetime
3
+
4
+
5
+ def main ():
6
+ print (time .timezone )
7
+ print (time .tzname )
8
+ print (time .localtime ())
9
+ print (time .localtime ().tm_isdst )
10
+ print (time .altzone )
11
+ utc_offset_sec = time .altzone if time .localtime ().tm_isdst else time .timezone
12
+ utc_offset = datetime .timedelta (seconds = - utc_offset_sec )
13
+ print (datetime .timezone (offset = utc_offset ))
14
+
15
+
16
+ if __name__ == '__main__' :
17
+ main ()
Original file line number Diff line number Diff line change
1
+ import time
2
+ import datetime
3
+
4
+
5
+ def main ():
6
+ local_now = datetime .datetime .now ()
7
+ print (local_now )
8
+ print (local_now .isoformat ())
9
+
10
+ utc_now = datetime .datetime .utcnow ()
11
+ print (utc_now )
12
+ print (utc_now .isoformat ())
13
+
14
+ # calculate the offset taking into account daylight saving time
15
+ utc_offset_sec = time .altzone if time .localtime ().tm_isdst else time .timezone
16
+ utc_offset = datetime .timedelta (seconds = - utc_offset_sec )
17
+ timezone = datetime .timezone (offset = utc_offset )
18
+ print (timezone )
19
+
20
+ local_now_with_tz = datetime .datetime .now ().replace (tzinfo = timezone )
21
+ print (local_now_with_tz )
22
+ print (local_now_with_tz .isoformat ())
23
+
24
+ utc_now_with_tz = datetime .datetime .utcnow ().replace (tzinfo = datetime .timezone .utc )
25
+ print (utc_now_with_tz )
26
+ print (utc_now_with_tz .isoformat ())
27
+
28
+
29
+ if __name__ == '__main__' :
30
+ main ()
31
+
32
+
33
+ # https://stackoverflow.com/a/28147286/3936457
You can’t perform that action at this time.
0 commit comments