Changing a string with a date into a format to get the day of the week

时间:2015-12-08 19:24:27

标签: ruby-on-rails ruby date

I have an input field that gives me a date in this format "Dec 22, 2015" and I need to get the day for the week out of it. I have tried taking the params and using the #:doc however I keep getting nil back.

This is the syntax I used:

strftime("%A")

I have seen from other posts I can do:

a = params[:start_date] 
a.strftime("%A")

and that works for t=Time.new t.strftime("%A") . I am not sure why it wouldn't work for my params.

1 个答案:

答案 0 :(得分:2)

You first need to convert the var icon = this.props.active ? require('./my-icon-active.png') : require('./my-icon-inactive.png'); <Image source={icon} /> into a String object.

Time

and then format it

require 'time'

t = Time.parse("Dec 22, 2015")