h0ax
h0ax

Reputation: 59

Timestamp in python (year,month,day,hour,minute)

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

Answers (2)

Prashant Kumar
Prashant Kumar

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

CDJB
CDJB

Reputation: 14546

You can use datetime.replace():

>>> datetime.now().replace(microsecond=0)
datetime.datetime(2020, 2, 4, 9, 24, 32)

Upvotes: 1

Related Questions