We’ve managed to print the date and time separately in a very pretty fashion. Let’s combine the two!
from datetime import datetime now = datetime.now() print '%02d/%02d/%04d' % (now.month, now.day, now.year) print '%02d:%02d:%02d' % (now.hour, now.minute, now.second)
The example above will print out the date, then on a separate line it will print the time.
Let’s print them all on the same line in a single
Print the date and time together in the form:
To start, change the format string to the left of the
- Ensure that it has five
- Put slashes and colons and a space between the placeholders so that they fit the format above.Then, change the variables in the parentheses to the right of the
- Place the variables so that
now.month, now.day, now.yearare before
now.hour, now.minute, now.second. Make sure that there is a
(before the six placeholders and a