Date and Time

stringhw6 stringhw5 stringhw4 stringhw3 stringhw2 stringhw1

This lab focuses on using string commands and import to create a program that captures the current date and time. Using the ‘=’ to set a value for a variable, a variable can be set to capture the current time and date. But what if we want to simplify it? Using the ‘.’, datetime commands , like “month, and print, we can print out specific parts of time.

What if we wish to set up a formula to capture specific part of time in a form? By using “%s” and “%”(insert words)”, we can create a formula that prints out the date in the standard mm/dd/yy. This can be done the same for time in the form of hh/mm/ss/

Here is the line of code used in the last part of the lab that captures both the month,day, year and the hours,minutes,seconds format.

from datetime import datetime
now = datetime.now()

print ‘%s/%s/%s %s:%s:%s’ % (now.month,now.day,now.year,now.hour, now.minute, now.second)