Creating time stamps

Albert-Jan Roskam sjeik_appie at hotmail.com
Mon Jul 22 17:27:38 EDT 2019



On 22 Jul 2019 23:12, Skip Montanaro <skip.montanaro at gmail.com> wrote:

Assuming you're using Python 3, why not use an f-string?

>>> dt = datetime.datetime.now()
>>> dt.strftime("%Y-%m-%d %H:%M")
'2019-07-22 16:10'
>>> f"{dt:%Y-%m-%d %H:%M}"
'2019-07-22 16:10'

===》》 Or if you're running < Python 3.6 (no f strings): format(datetime.now(), "%Y-%m-%d %H:%M")


More information about the Python-list mailing list