-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpy_time.py
More file actions
39 lines (30 loc) · 899 Bytes
/
py_time.py
File metadata and controls
39 lines (30 loc) · 899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import datetime
import time
import pytz
# ------------------------------------
# `datetime.time(hr,min,sec,ms, tmz)`
# Naive by default. Can be made aware.
# ------------------------------------
h, m, s, ms = 9,38,45,100000
# Integers to time
# > 09:38:45.100000
naive_time = datetime.time(h,m,s,ms)
print(f'Integers to Time: {naive_time}')
# String to time
# >
# Time to ISO
# >
# Current naive local time
# >
dt_local = time.localtime()
print(f'Local Time: {dt_local}')
# Local time to string
# Format describes INPUT - not output.
# > 2022-02-27 17:32:51
dt_local_string = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
print(f'Local Time to String: {dt_local_string}')
# Extracting integers from time
print(f'Time Hours: {naive_time.hour}')
print(f'Time Minutes: {naive_time.minute}')
print(f'Time Seconds: {naive_time.second}')
print(f'Time Micro: {naive_time.microsecond}')