Lab 3: Date and Time

Lab Description:

In this lab I used codecademy to create a code to print the date and time in a more organized way.  I had to use the function datetime.now() in order to get the correct and current date in the format of month, day, year.  I also used the same function to get the current time in hour, minutes, seconds.  To get all the current date and time I had to use the (+) concatenation to get all the data on one line.

Source Code:

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

Screen Shot:

navin

Leave a Reply

Your email address will not be published. Required fields are marked *