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

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -