if I have an array of dates:
["2012-1-1", "2012-1-3","2012-5-3"]
I want to be able to get a result list of:
["January 2012", "May 2012"]
What is the best way to do this?
if I have an array of dates:
["2012-1-1", "2012-1-3","2012-5-3"]
I want to be able to get a result list of:
["January 2012", "May 2012"]
What is the best way to do this?
[datetime.datetime.strptime(d, '%Y-%m-%d').strftime("%B %Y") for d in my_list]
如果您想按日期时间排序并剔除唯一性,我将分三部分执行此操作:
dates = [datetime.datetime.strptime(d, '%Y-%m-%d') for d in my_list]
dates.sort()
string_dates = [d.strftime("%B %Y") for d in dates]
## now we'll cull the list of duplicates
import itertools
[ grouped[0] for grouped in itertools.groupby(string_dates) ]