简体   繁体   中英

Covert datetime64[ns, UTC] to datetime64 python

I have a column with datetime UTC date

2020-01-01 00:00:00+00:00   

Can someone help me to convert it to just datetime64 for eg:

2020-01-01 

if you use pandas (this seems to be the case) you can change it like that:

df.dates.apply(lambda x: x.date()) # where dates is your datetime column

Try the datetime package with Python 3.2+.

import datetime
a='2020-01-01 00:00:00+00:00'
print (datetime.datetime.strptime(a,'%Y-%m-%d %H:%M:%S%z').strftime('%Y-%m-%d'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM