Lab Description:
The purpose of this lab is to show students how to display the date using different formats and the time from hours to seconds including minutes using the programming language called Python. Programmer use the “datetime.now()” module to display the time or date of various events or the current day on their programs. In order for the module to work properly we have to set a variable to it. In this lab the variable for datetime.now() should be “now” and we have to make it as a statement by typing it in the console as it is displayed in step 2. After the variable “now” is set, we can type “print now” and it would display the present date and current time. The time is displayed as hh:mm:ss and the date is displayed as YYYY-MM-DD. You can display the date and time separately using different formats which is shown in a later step. Step 3 shows how you can make Phyton display each part of the date separately by just typing ‘”print now.”part of the date you want to show”‘ For example, the “print now.year” would display the current year and the “print now.day” would display the current day. Step 4 show that you can print a string that displays the date in specific format. The “%” would replace the “%s” by the variable values in parenthesis. The “%s” is the position in which the variable value would appear. For example, ‘”print “%s/%s/%s” % (now.month, now.day, now.year) displays 09/13/2017. Step 5 shows another format using the time instead of date where the “/” with “:” and inside the parenthesis are “now.hour, now.minute, now. second” which shows the time, And lastly you can make python display both the date and time by just typing ‘”print “%s/%s/%s %s:%s:%s” % (now.month, now.day, now.year, now.hour, now.minute, now. second).