【发布时间】:2017-12-08 00:22:15
【问题描述】:
我正在尝试根据一天中的时间显示一条消息,我目前有这段代码:
<% if Time.now >= "7:00" and Time.now <= "14:00" %>
Good Morning <%= current_user.nome %>! <br>
<% else %>
Good Afternoon <%= current_user.nome %>!
<% end %>
现在是 14:30,页面仍然显示Good Morning (username),此时应该显示Good Evening (username)
- 我的代码错了吗?
- 我该如何解决这个问题?
【问题讨论】:
-
你打印
Time.now的返回了吗? -
你能比较一下
String和Time吗? -
2017-07-04 14:54:14 +0100这是时间。现在 -
那你如何比较
time和time?
标签: ruby-on-rails ruby time