Answers for "python get current time datetime"

7

python show current time

from datetime import datetime

now = datetime.now()

current_time = now.strftime("%H:%M:%S")
print("Current Time =", current_time)
Posted by: Guest on April-29-2020
7

print time python

from datetime import datetime

now = datetime.now().time() # time object

print("now =", now)
print("type(now) =", type(now))
Posted by: Guest on March-22-2020
7

get current time python

from datetime import datetime as d
import time as t
from os import system as clear
cls = lambda: clear("clear")

prev = d.now()
prev = prev.strftime("%Y-%m-%d %H:%M:%S")

while True:
  time = d.now()
  time = time.strftime("%Y-%m-%d %H:%M:%S")
  print(time)
  if not time == prev:
    prev = time
  t.sleep(1)
  cls()
Posted by: Guest on December-15-2020
3

python get current time

---------------------------------------------------------
import datetime
 
currentDateTime = datetime.datetime.now()
print(currentDateTime)
---------------------------------------------------------
OR
---------------------------------------------------------
from datetime import datetime
 
currentDateTime = datetime.now()
print(currentDateTime)
---------------------------------------------------------
OR
---------------------------------------------------------
import datetime

print(datetime.datetime.now())
---------------------------------------------------------
OR
---------------------------------------------------------
from datetime import datetime
 
print(datetime.now())
---------------------------------------------------------
Posted by: Guest on February-16-2021

Code answers related to "python get current time datetime"

Python Answers by Framework

Browse Popular Code Answers by Language