- In the previous example…we saw how to retrieve…basic date and time information in Python.…So now we'll take a look at how to format that information…using a set of predefined string control codes.…In your editor,…open up the formatting_start file…and in this example file…you can see I've already set up the import statement…to import the datetime class,…so you don't need to do that.…Python provides a standard set of string formatting codes…that you can use in a variety of scenarios.…
And if you've ever done any programming in C or a C++…and you've used the standard C library,…then these codes might look familiar to you.…If not, they're pretty easy to understand…once you've seen them.…So let's start…with a familiar piece of code…to get the current date and time.…So I'll write now = datetime.now…and we saw this in the previous example.…So now that I've got the current date and time,…let's take a look at some of the options I have available…to me to format the output.…
To format date information…you use the stirftime function…
- Installing Python
- Choosing an editor or IDE
- Working with variables and expressions
- Writing loops
- Using the date, time, and datetime classes
- Reading and writing files
- Fetching internet data
- Parsing and processing HTML
Skill Level Beginner
1. Getting Started
2. Python Basics
3. Working with Dates and Time
4. Working with Files
5. Working with Web Data
- 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.