Skip to content Skip to sidebar Skip to footer

Python Format Date Using Only String Format() Method

What is the quick way to format date in python using only .format method? I know there is a way to do it without using strftime. I need more elegant method.

Solution 1:

I know a good method which is not widely known, but very useful.

Here is how you can do it:

from datetime import datetime
'{:%Y-%m-%d %H:%M}'.format(datetime(2018, 12, 28, 10, 30))

The output is 2018-12-28 10:30

Post a Comment for "Python Format Date Using Only String Format() Method"