now I have datetime like mintt
In [134]: mintt
Out[134]: datetime.datetime(2012, 5, 9, 23, 21, 10, 548382, tzinfo=<matplotlib.dates._UTC object at 0x2f805d0>)
and I change it like this:
In [131]: mintt.isoformat(" ").split(".")[0]
Out[131]: '2012-05-09 23:21:10'
how can I delete the minute and seconds,let it become “2012-05-09 23:00:00” ?
PS:at the beginning I use method below:
In [135]: mintt.strftime('%Y-%m-%d %H:00:00')
Out[135]: '2012-05-09 23:00:00'
but it will raise an exception like’ year=1601 is before 1900; the datetime strftime() methods require year >= 1900′
so I use isoformat method
Use the
datetime.replace()method.This doesn’t change
t, it creates a new object.