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
Post a Comment