小时和分钟的时间......请建议我

时间:2013-12-05 09:05:39

标签: ruby-on-rails-3

for login_details我正在计算登录和注销之间的时间,但它的计算时间仅为几分钟,需要小时和分钟。请帮助我并编写如下代码

   <table>
  <%count = 1%>
      <%@login_info.each do |l| %>
       <tr>
        <td><%= count%></td>
        <td><%=l.user.name%></td>
        <td><%=Location.find(l.location_id).name%></td>
        <td><%=showdatetime(l.login_time)%></td>
        <td><%=showdatetime(l.logout_time)%></td>

     <td> <%= time=(l.logout_time.minus_with_coercion(l.login_time)/60)%>minutes</td>  


        </tr>
     <%count = count+1%>          
      <%end%>
    </table>

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

查看此代码

       <%count = 1%>
         <%@login_info.each do |l| %>
       <tr>
        <td><%= count%></td>
        <td><%=l.user.name%></td>
        <td><%=Location.find(l.location_id).name%></td>
        <td><%=showdatetime(l.login_time)%></td>
        <td><%=showdatetime(l.logout_time)%></td>

          <td>
     <%seconds = l.logout_time.to_i - l.login_time.to_i%>
     <% days = seconds / 86400%>
   hours = seconds / 3600%>
 <%minutes = (seconds - (hours * 3600)) / 60%>
       <%= hours.to_s + "hr" + minutes.to_s + "min"%></td>  


        </tr>
     <%count = count+1%>          
      <%end%>