
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Display Various DateTime Formats in Python
The datetime module supplies classes for manipulating dates and time. We will display different formats like day of the week, week number, day of the year, etc.
Algorithm
Step 1: Import datetime. Step 2: Print day of the week. Step 3: Print week number. Step 4: Print day of the year.
Example Code
import datetime print("Day of the week: ", datetime.date.today().strftime("%A")) print("Week number: ", datetime.date.today().strftime("%W")) print("Day of the year: ", datetime.date.today().strftime("%j"))
Output
Day of the week: Sunday Week number: 06 Day of the year: 045
Explanation
The arguments of the strftime() function are explained below:
- %A: Weekday's full name (Example: 'Monday')
- %W: Week number of the year with sunday as first day of the week
- %j: Day of the year as a zero padded decimal number
Advertisements