Topic: 12 Hour Date & Time Select

I love the ease in which Ruby on Rails handles date & time for forms. However, I hate the fact that by default there is not a 12-hour/24-hour option. When developing a public application I want to be able to stick with the standard Rails methods but have the option for 12-hour time with a AM/PM select. That's where the 12-Hour Time Plugin comes into play.

You can use the normal date and time method:

<%= datetime_select :post, :created_at %>

and have this as your output:
http://www.dan-reedy.com/uploads/datetime_select.png

All you need to do is go here: http://www.nickm.org/svn/repos/rails/pl … hour_time/ and save those files into a folder called 12_hour_time in your rails/plugins directory and you're off and running, no additional configuration needed.

Most code examples are usually pulled out of the air and not tested. Use at your own risk!

2

Re: 12 Hour Date & Time Select

Nice! I was thinking about something like this the other day. I may try doing a version that puts the am/pm in the hour select. That way you only have one select to make. 12 am/pm can get confusiing, so maybe have 'Noon' and 'Midnight' in place of the '12' options. Hmm. I wonder what time Midnight:30 would be. Heh.

Re: 12 Hour Date & Time Select

You can use Fix Date Plugin for that effect I believe. I like the separate AM/PM select myself, I think it looks a little cleaner.

Last edited by Reedy (2006-06-25 23:18:46)

Most code examples are usually pulled out of the air and not tested. Use at your own risk!