python - Setting the time of datetime.now() -


i trying current datetime , set time 00:00:00.

to this, call:

current_date = dt.datetime.now() current_date.replace(hour=0, minute=0, second=0) print(current_date) 

the output is:

2017-08-20 10:43:56.3243245 

that not expect. however, if do:

current_date = dt.datetime(dt.datetime.now().date().year,dt.datetime.now().date().month,dt.datetime.now().date().day,0,0,0) 

everything expect , result:

2017-08-20 00:00:00 

why this? going on?? why replace not work?

replace returns new datetime instance, should do:

>>> current_date = dt.datetime.now() >>> current_date = current_date.replace(hour=0, minute=0, second=0, microsecond=0) >>> print(current_date) 2017-08-20 00:00:00 

you should replace microsecond=0 in order make 00:00:00.


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -