时间字符串 操作

str -> date

import datetime

detester = ‘2017-01-01'
date = datetime.datetime.strptime(detester,’%Y-%m-%d')

date -> str

1 import datetime
2 
3 date = datetime.now()
4 
5 detester = date.strftime(‘%Y-%m-%d')
# td['purchase-date']   是数据框 dataframe中的一列

for x in td['purchase-date']:
    nPos = x.index('T')
    print(x[:nPos])


# 上面方法 等同于 


[x[:x.index('T')]) for x in td['purchase-date']]

  

猜你喜欢

转载自www.cnblogs.com/UpThinking/p/9496961.html