From: Brian Candler Date: 2011-07-20T01:41:43+09:00 Subject: Re: How to change date format from Y/m/d to Y-m-d liu skywalker wrote in post #1011661: > 于 2011年07月19日 21:42, Annie smith 写道: >> Hi All, >> >> Do you know how to change date format from Y/m/d to Y-m-d in ruby? >> >> Thanks! >> > def convert!(time) > time=times.split("/").join("-") > end > convert!("2011/11/11) Aside 1: it's unconventional to put an exclamation mark at the end of a method name, if the method does absolutely nothing dangerous, nor does it modify the receiver. Aside 2: no need to assign the result. Also, 'times' is not known. Here's a corrected version: def convert(time) time.split("/").join("-") end Here's an alternative one: def convert(time) time.gsub(%r{/}, '-') end -- Posted via http://www.ruby-forum.com/.