Honestly, since you only have two months that are different, I would probably just gsub
them:
DateTime.strptime("10 okt 2009 04:32".gsub(/okt/,'Oct'),'%d %b %Y %H:%M')
If you want, you can put this in a little helper:
def swedish_to_english_date(date_string) date_string.gsub(/may|okt/, 'may' => 'May', 'okt' => 'Oct') end DateTime.strptime(swedish_to_english_date("10 okt 2009 04:32"),'%d %b %Y %H:%M')
Edit: note that gsub
with a hash as the second argument is thing 1.9, in 1.8 you can do something like
>> months = { 'may' => 'May', 'okt' => 'Oct' } => {"okt"=>"Oct", "may"=>"May"} >> "may okt".gsub(/may|okt/) { |match| months[match] } => "May Oct"
source share