Ruby 我怎样才能拉一个日期';从一个场景示例中选择s编号,并使用它在adv中移动我的日期x天,然后将其转换为STRFTIME?
我在理解如何从“从现在起2天”中去掉数字“2”,然后用它将日期增加两天时遇到了问题。所以像date=(date.today+2).strftime(“%a%-e”)这样的东西意味着向前两天 我的“看跌期权”只是为了查看是否输出了正确的日期。在这种情况下,我遇到了第三个案例的问题 如你所见,我需要逐字逐句地记录“星期四26个任务”的日期 作为你的想法结束Ruby 我怎样才能拉一个日期';从一个场景示例中选择s编号,并使用它在adv中移动我的日期x天,然后将其转换为STRFTIME?,ruby,datetime,case,strftime,Ruby,Datetime,Case,Strftime,我在理解如何从“从现在起2天”中去掉数字“2”,然后用它将日期增加两天时遇到了问题。所以像date=(date.today+2).strftime(“%a%-e”)这样的东西意味着向前两天 我的“看跌期权”只是为了查看是否输出了正确的日期。在这种情况下,我遇到了第三个案例的问题 如你所见,我需要逐字逐句地记录“星期四26个任务”的日期 作为你的想法结束 date=“3天后” date=“#{(date.today+date.match(/\A\d+(?!从现在算起的天数\z)/)[0]。如果da
date=“3天后”
date=“#{(date.today+date.match(/\A\d+(?!从现在算起的天数\z)/)[0]。如果date.match(/\A\d+从现在算起的天数\z/),则返回到_i.strftime(“%A%-e”)}任务”
#=>“周五29项任务”
date.match?(/\A\d+days from now\z/)
返回true
或false
date.match(/\A\d+(?!从现在算起的天数\z)/)[0]
返回包含天数数量的子字符串(“3”
)
否定前瞻>代码>(…..)>代码> >
什么是<代码>和<代码>?如果您确信“代码>日期<代码>以数字开头,您可以简单地使用<代码> DAT.ToII<代码>来获得其整数值。如果您发现任何一个答案有用,请考虑选择一个。require 'date'
def doit(str)
n = case str
when /\btoday\b/
0
when /\btomorrow\b/
1
when /\bdays from now\b/
str[/\d+/].to_i
else
nil
end
n.nil? ? nil : (Date.today+n).strftime('%a %-e Tasks')
end
doit "today" #=> "Tue 26 Tasks"
doit "No rain today?" #=> "Tue 26 Tasks"
doit "todayornottoday" #=> nil
doit "tomorrow" #=> "Wed 27 Tasks"
doit "2 days from now" #=> "Thu 28 Tasks"
doit "1 Monday from now" #=> nil
require 'date'
def doit(str)
n = case str
when /\btoday\b/
0
when /\btomorrow\b/
1
when /\bdays from now\b/
str[/\d+/].to_i
else
nil
end
n.nil? ? nil : (Date.today+n).strftime('%a %-e Tasks')
end
doit "today" #=> "Tue 26 Tasks"
doit "No rain today?" #=> "Tue 26 Tasks"
doit "todayornottoday" #=> nil
doit "tomorrow" #=> "Wed 27 Tasks"
doit "2 days from now" #=> "Thu 28 Tasks"
doit "1 Monday from now" #=> nil