Is there a strftime format I'm missing that would get a time to display as 8:30 PM instead of 08:30 PM? Using @mytime.strftime(" %I:%M %p") gives me a display like 08:30 PM, but I'd like it to show as h:mm and not hh:mm for times earlier than 10:00. Thanks.
I guess it's fairly popular:
WordPress
Error establishing a database connection
Time#strftime uses the platform function with the same name, this might be platform dependent but on both OSX and Ubuntu linux,
@mytime.strftime("%l:%M %p") #=> " 8:30 pm"
Note that that first format character is a lowercase L not an uppercase I.
Also lowercase k will do the same thing but use military time.
Note that this suppresses the leading zero, but does put a blank in it's place. If you really want to get write of the leading blank, just do:
@mytime.strftime("%l:%M %p").strip
Rick DeNatale wrote:
That works on the Windows system I'm developing on as well as my Linux host. Thanks!
@mytime.strftime("%I:%M %p") alone didn't show the hour at all on a Windows system.