How to format date and time in Python

2 Answers

0 votes
import datetime

format = "%b %d %Y - %H:%M:%S"

dt = datetime.datetime.today()

f = dt.strftime(format)

print(f)



'''
run:

Jun 06 2019 - 14:36:56

'''

 



answered Jun 6, 2019 by avibootz
0 votes
import datetime

format = "%A %d %Y - %H:%M:%S"

dt = datetime.datetime.today()

f = dt.strftime(format)

print(f)



'''
run:

Thursday 06 2019 - 14:38:37 

'''

 



answered Jun 6, 2019 by avibootz
...