Hi All,
Do you know how to change date format from Y/m/d to Y-m-d in ruby?
Thanks!
···
--
Posted via http://www.ruby-forum.com/.
Hi All,
Do you know how to change date format from Y/m/d to Y-m-d in ruby?
Thanks!
--
Posted via http://www.ruby-forum.com/.
Check out strftime.
`ri strftime`
Lake
Sent from my iPhone
On Jul 19, 2011, at 9:42 AM, Annie smith <annie.smith.vufind@gmail.com> wrote:
Hi All,
Do you know how to change date format from Y/m/d to Y-m-d in ruby?
Thanks!
--
Posted via http://www.ruby-forum.com/\.
Annie smith wrote in post #1011629:
Hi All,
Do you know how to change date format from Y/m/d to Y-m-d in ruby?
Thanks!
DateTime.now.strftime("%Y-%m-%d")
--
Posted via http://www.ruby-forum.com/\.
于 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)
Lake Denman wrote in post #1011635:
Check out strftime.
`ri strftime`
Lake
Sent from my iPhone
Thanks!
--
Posted via http://www.ruby-forum.com/\.
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/\.