Date and Time

Datetime.

We began this lab by first obtaining the datetime library. Using the function datetime.now(), then we use print datetime.now() to retrieve the current date and time. We then took the year from the variable now and stored it in current_year, doing the same for the month and day. Using print current_year, current_month and current_day, it listed each command separately. Next we rearranged to the following mm/dd/yyyy format, using a / character to replace the – character. To print the current time we just replaced (now.month, now.day, now.year) with (now.hour, now.minute, now.second) and replaced the / character with a : character. Finally combining the format strings together with a space in between the combination, then combining the variable of both current date andĀ current time.Ā Receiving the mm/dd/yyyy Ā hh:mm:ss format we desired.

Leave a Reply

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