In this video, Kathryn shows you how to use the datetime module to format the current time retrieved in the previous video. She demonstrates using the strftime function to make the datetime look more recognizable to the user.
Now, everything we've written so far has only come in…one format, but we can actually control the format of our…dates and times with strings.…We'll use something called "shift time"…with he shift time method.…It takes one string, and what's in the string determines…how the contents of the "now" variable are displayed.…First, we'll control how the day of a given week or month…is displayed.…With %a we can have an abbreviated day of the week…with just Mon, Tues, Wed displayed.…With %A, we can show the full name of the day of the week.…
So Monday, Tuesday, et cetera.…And we can also display the day as the day of the month…with %d.…So if it was going to be the tenth day of the month,…%d would translate to ten.…Trying this out we'll go…now dot S-T-R-F-T-I-M-E,…%a, %A and then %d.…So this will display the abbreviated day of the week,…the full day of the week, and then the numbered day…of the week.…
Printing this out we'll add a print statement here.…Run the code.…And we get Wed Wednesday and it's the fourteenth…of the month.…
- Working with logical and comparison operators
- Getting a list of numbers with the range() and list() functions
- Using mathematical functions such as round(), abs(), and pow()
- Calculating a given input's length
- Importing and using the math module
- Reading a user's command-line arguments
- Getting the current time
- Formatting dates and times with datetime
- Creating a timer
- Using urllib to get content from the Internet
- Using the JSON module to decode content
Skill Level Intermediate
1. Python: What's Built-In?
2. Python: Math
3. Python: Input/Output
4. Python: Date & Time, HTML Parsing, and HTTP
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.