本文介绍了在 ruby​​ on rails 中迭代日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个用于报告和分析的应用程序,我需要每天生成数据并将其放入 CSV 文件中.更清楚地说,如果我今天像第一天一样接受报告,我如何获得报告已经做好了,如果明天拿到报告,我应该可以得到今天,昨天的数据.如果我在 4 天后拿到报告,我应该从第 1 天到第 4 天收到报告.

I am developing an application for reporting and analytic,where I need to generate data on a daily basis and put it in a CSV.To be more clear, if I take the report today like day one any how I can get the report thats already done, if I get the report tomorrow I should be able to get the data of today,yesterday. If i take after 4 days I should get the report starting from day 1 to day 4.

如何做到.寻找抬头

推荐答案

这个怎么样:

today = Date.today
tomorrow = today.next
four_days_ago = 4.days.ago(today)
four_days_later = 4.days.since(today)
(today..(4.days.since(today)).each {|d| puts d}

这篇关于在 ruby​​ on rails 中迭代日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-20 23:06