Lesson 22: Date & times

posted Apr 13, 2018, 7:59 AM by Attila Lengyel
from datetime import datetime

now = datetime.now()
print(now)

mm = str(now.month)
print(mm)

dd = str(now.day)
print(mm + "/" + dd)

yyyy = str(now.year)
print(mm + "/" + dd + "/" + yyyy)

hh = str(now.hour)
print(mm + "/" + dd + "/" + yyyy + " " + hh)

mi = str(now.minute)
print(mm + "/" + dd + "/" + yyyy + " " + hh + ":" + mi)

sec = str(now.second)
print(mm + "/" + dd + "/" + yyyy + " " + hh + ":" + mi + ":" + sec)

def printtime():
  timenow = datetime.now()
  mm2 = str(timenow.month)
  dd2 = str(timenow.day)
  yyyy2 = str(timenow.year)
  hh2 = str(timenow.hour)
  mi2 = str(timenow.minute)
  sec2 = str(timenow.second)
  print(mm2 + "/" + dd2 + "/" + yyyy2 + " " + hh2 + ":" + mi2 + ":" + sec2)
  

import time
for x in range(0,5):
  printtime()
  time.sleep(1)

print("please write your name")
n1 = datetime.now()
name = input("Give me your name:")
n2 = datetime.now()
print("It took you " + str(n2-n1))

Comments