Sharon Machlis
2007-Nov-27 14:03 UTC
Format for getting time to display as 8:30 PM not 08:30 PM?
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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Tom Taylor
2007-Nov-27 20:25 UTC
Re: Format for getting time to display as 8:30 PM not 08:30
Sharon Machlis wrote:> 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.Funnily enough, my colleague just blogged about this... http://infovore.org/archives/2007/11/27/displaying-the-number-of-hours-without-a-leading-zero-in-rubys-strftime/ -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Greg Donald
2007-Nov-27 20:29 UTC
Re: Format for getting time to display as 8:30 PM not 08:30
On Nov 27, 2007 2:25 PM, Tom Taylor <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> Funnily enough, my colleague just blogged about this... > > http://infovore.org/archives/2007/11/27/displaying-the-number-of-hours-without-a-leading-zero-in-rubys-strftime/I guess it''s fairly popular: WordPress Error establishing a database connection -- Greg Donald http://destiney.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Shandy Nantz
2007-Nov-27 20:49 UTC
Re: Format for getting time to display as 8:30 PM not 08:30 PM?
Sharon Machlis wrote:> 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.Well I''m not using strftime and it is a little long winded but I do have code that does what you ask: <%= Time.now.hour < 10 ? Time.now.hour + '' AM'' : Time.now.hour.to_i > 12 ? (Time.now.hour.to_i - 12).to_s + '' PM'' : Time.now.hour + '' PM'' %> Hope this helps, -S -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rick DeNatale
2007-Nov-27 21:09 UTC
Re: Format for getting time to display as 8:30 PM not 08:30 PM?
On Nov 27, 2007 9:03 AM, Sharon Machlis <smachlis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > 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.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 My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Gary Doades
2007-Nov-27 21:15 UTC
Re: Format for getting time to display as 8:30 PM not 08:30 PM?
Rick DeNatale wrote:> On Nov 27, 2007 9:03 AM, Sharon Machlis <smachlis-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> 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. > > 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. >You can do: @mytime.strftime("%I:%M %p").sub(/^0/,'''') This should work on all platforms I think. Cheers, Gary. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Sharon Machlis
2007-Dec-23 02:08 UTC
Re: Format for getting time to display as 8:30 PM not 08:30 PM?
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. On Nov 27, 4:15 pm, Gary Doades <g...-UVRRe/+0hzLQXOPxS62xeg@public.gmane.org> wrote:> You can do: > > @mytime.strftime("%I:%M %p").sub(/^0/,'''') > > This should work on all platforms I think. > > Cheers, > Gary.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---