Python format date using only string format() method

后端 未结 1 828
小蘑菇
小蘑菇 2021-01-26 05:29

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 me

相关标签:
1条回答
  • 2021-01-26 05:48

    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

    0 讨论(0)
提交回复
热议问题