我有一个代码错误地生成它,我认为必须有一个更好的方式来检查时间>上午9时30分,时间< 4 pm
任何想法都高度赞赏.
任何想法都高度赞赏.
- def checkTime
- goodtime=false
- if(Time.now.hour>9 and Time.now.min>30) then
- if(Time.now.hour<16) then
- goodtime=true
- else
- # do nothing
- end
- elsif Time.now.hour>9 and Time.now.hour<16 then
- goodtime=true
- else
- # do nothing
- end
- return goodtime
- end
解决方法
- t = Time.now
- Range.new(
- Time.local(t.year,t.month,t.day,9),Time.local(t.year,16,30)
- ) === t