Python strftime: Format Dates and Times
This Snippet is coded by a user inOnline python Compiler. You can see and run this code too.
زبان: python
This code demonstrates how to use Python's strftime method to format datetime objects into readable strings. The datetime module is imported, and a datetime object is created for January 1, 2022, at 12:30:00. The strftime method is then called with various format codes to produce different representations.
Here are the format codes used:
%Y– 4-digit year%m– 2-digit month%d– 2-digit day%A– full weekday name%B– full month name%a– abbreviated weekday name%b– abbreviated month name%y– 2-digit year%H– 24-hour hour%M– minute%S– second%p– AM/PM
By combining these codes with separators, you can customize the output format as needed.