Date and time

Lab description: Using the datetime.now() command, and setting the correct variables, we can set the time and the date of the current time. We can use that to set the current time.  By using str, quotation mark, and plus sign we can print the time and date correctly.

Source code

from datetime import datetime
now=datetime.now()
current_hour=now.hour
print (now.hour)
current_minute=now.minute
print (now.minute)
current_second=now.second
print (now.second)
current_year= now.year
print (now.year)
current_month=now.month
print(now.month)
current_day=now.day
print(now.day)
print str (now.month)+”/”+ str(now.day)+”/”+ str(now.year), str(now.hour)+”:”+ str(now.minute)+”:”+ str(now.second)

Screenshot

lab 4

Leave a Reply