Formatting Timestamps for Readability
00:00
If you’d like to make your outputs more readable, you can use the .strftime()
method on your datetime object. The .strftime()
method takes format codes as arguments.
00:10
Format codes are placeholders within a string, which are replaced with specific values when the code is executed. In the example that you’ll be shown, you will see the following three format codes used: %A
, which will return the current weekday; %B
, which will return the current month’s full name.
00:30
You’ll also see %d
, which will return the numeric day of the month.
00:36
Inside the method, you can write the following string, which states Today is %A
, which is the current weekday, %B
, which is the current month, and %d
, which is the current day.
00:50
Upon executing the code, you can see that Python returns Today is
Sunday, October 01`. There are many more format codes that you can use within the .strftime()
method.
01:00 For a handy cheat sheet, you can head over to strftime.org.
01:05 In the next lesson, you will learn about what Unix time is the importance of it in programming, as well as how to work with it in Python.
Become a Member to join the conversation.