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?
You have to pass the format using value
key.
<div class=".col-md-7">
<%= f.label :recieved %><br>
<%=
f.time_field :recieved,
value: "%H:%M",
min: 'hh:mm:ss',
max: 'hh:mm:ss'
%>
</div>
The doc says:
The default value is generated by trying to call strftime with “%T.%L” on the objects's value. It is still possible to override that by passing the “value” option.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With