Psst! Check what courses we have in our offer, and get them all here to save $727. Act fast–this deal is available only 3/14–3/21.
Introduction
Placeholders
Numbers
Date and time
11. Formatting datetime—other symbols
Padding and Alignment
Summary

Instruction

Perfect! Actually, there are many more symbols that you can use when formatting dates, not just %H, %M, %d,%m, and %Y. For instance:

from datetime import datetime
my_birthday_party = datetime(2018, 10, 3, 16, 0, 0)
'{:%A %I:%M %p}'.format(my_birthday_party)

Result: Wednesday 04:00 PM

As you can see, %A shows the weekday, and %I prints the hour in the 12-hour format. %p prints AM or PM.

You can find other symbols for date formatting at Python's documentation.

Exercise

Format the important_meeting variable, and print the following sentence:

I have a very important meeting on Tuesday, 02:25 PM.

Stuck? Here's a hint!

You will need to use the following symbols:

  • %A
  • %I
  • %M
  • %p