Reputation: 59
Currently im using
datetime.now()
The result im getting is for example
datetime.datetime(2020, 2, 4, 10, 14, 20, 768814)
My goal is to get
datetime.datetime(2020, 2, 4, 10, 14, 20)
Upvotes: 2
Views: 1166
Reputation: 2092
Its simple. If you don't want the microseconds, use below:
datetime.now().replace(microsecond=0)
Output ---> datetime.datetime(2020, 2, 4, 14, 53, 44)
Upvotes: 0
Reputation: 14546
You can use datetime.replace()
:
>>> datetime.now().replace(microsecond=0)
datetime.datetime(2020, 2, 4, 9, 24, 32)
Upvotes: 1