1
2from datetime import datetime
3
4now = datetime.now()
5
6current_time = now.strftime("%H:%M:%S")
7print("Current Time =", current_time)
8
1from datetime import datetime as d
2import time as t
3from os import system as clear
4cls = lambda: clear("clear")
5
6prev = d.now()
7prev = prev.strftime("%Y-%m-%d %H:%M:%S")
8
9while True:
10 time = d.now()
11 time = time.strftime("%Y-%m-%d %H:%M:%S")
12 print(time)
13 if not time == prev:
14 prev = time
15 t.sleep(1)
16 cls()
17
1import time
2
3t = time.localtime()
4current_time = time.strftime("%H:%M:%S", t)
5print(current_time)
6
1---------------------------------------------------------
2import datetime
3
4currentDateTime = datetime.datetime.now()
5print(currentDateTime)
6---------------------------------------------------------
7OR
8---------------------------------------------------------
9from datetime import datetime
10
11currentDateTime = datetime.now()
12print(currentDateTime)
13---------------------------------------------------------
14OR
15---------------------------------------------------------
16import datetime
17
18print(datetime.datetime.now())
19---------------------------------------------------------
20OR
21---------------------------------------------------------
22from datetime import datetime
23
24print(datetime.now())
25---------------------------------------------------------
1from datetime import datetime
2
3now = datetime.now()
4
5current_time = now.strftime("%H:%M:%S")
6print("Current Time =", current_time)
1from datetime import datetime as d
2import time as t
3from os import system as clear
4cls = lambda: clear("clear")
5
6prev = d.now()
7prev = prev.strftime("%Y-%m-%d %H:%M:%S")
8
9while True:
10 time = d.now()
11 time = time.strftime("%Y-%m-%d %H:%M:%S")
12 print(time)
13 if not time == prev:
14 prev = time
15 t.sleep(1)
16 cls()