'f.time_field with 24 hour clock - Rails Fields
I've got a little Rails app that I need to use the 24-hour clock for inputting times. Right now, I've got:
<div class=".col-md-7">
<%= f.label :backinservice %><br>
<%= f.time_field :backinservice %>
</div>
Which gives an AM/PM option. When I input a time like 18:56, it automagically converts it to 06:56 PM. Normally that would be totally ok, just not in this app.
I also tried:
<div class=".col-md-7">
<%= f.label :recieved %><br>
<%= f.time_field :recieved, :format=>"%H:%M" %>
</div>
But that doesn't work either.
Is there a :format option that allows for straight use of the 24-hour clock?
Solution 1:[1]
I had to do the following to get this to work for me:
<%=
f.time_field :my_time_field,
value: f.object.my_time_field.strftime("%H:%M")
%>
Found this out by looking at the definition of time_field, that is only creating a new instance of Tags::TimeField.new
In turn Tags::TimeField.new only does one thing which is to define the format.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mr. Ronald |
