I’m trying to get hours, minutes and seconds from current time and print it into format “hourminutesecond”. For example “121103”. But there isn’t printed leading zero when I try to do it with next code
irb(main):021:0> ct = Time.now
=> 2012-11-06 12:11:03 +0100
irb(main):022:0> "#{ct.hour}#{ct.min}#{ct.sec}"
=> 12113
Output is “12113” but I want “121103”.
Is there method or option for that. I can extract it with regex but just wondering if there is easier way to do it.
You should use time formatting: