Hi All,
Do you know how to change date format from Y/m/d to Y-m-d in ruby?
Thanks!
Hi All,
Do you know how to change date format from Y/m/d to Y-m-d in ruby?
Thanks!
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")
Check out strftime.
ri strftime
Lake
Sent from my iPhone
于 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)
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
Lake D. wrote in post #1011635:
Check out strftime.
ri strftime
Lake
Sent from my iPhone
Thanks!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs