'how to print time in python in customized format? [duplicate]

how can I print time in format using python

220429

first two letters are last two digits of 2022, midle one are month and last two are day in a month



Solution 1:[1]

You can do so using the strftime method on datetime objects.

from datetime import datetime

d = datetime.now()

d.strftime('%y%m%d') # Outputs '220429'

strftime() and strptime() Behavior

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 theherk