- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to display various datetime formats
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.
Step 1: Import datetime. Step 2: Print day of the week. Step 3: Print week number. Step 4: Print day of the year.
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"))
Day of the week: Sunday Week number: 06 Day of the year: 045
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
- Display years in different formats with C# DateTime
- Java Program to set date formats for different countries
- C program to print characters and strings in different formats.
- How to print the numbers in different formats using C program?
- How to use Formats in Perl?
- Java Program to create custom DateTime formatter
- What are Instruction Formats?
- Difference between various Implementations of Python?
- Python program to Display Hostname and IP address?
- Python Program to Display Fibonacci Sequence Using Recursion
- How to convert date to datetime in Python?
- How to convert Python datetime to epoch with strftime?