ruby - how to format `20134859` into `20 - 13:48:59` -


is there nice (maybe 1 line) way how format

20134859 20 - 13:48:59 ??

i started "20134859".unpack('a2a*').join(' - ') don't know how tackle : thinking if or how can split , join(':') second element return unpack. in 1 line.

this works sure there out there i'll more

s = "20134859" "#{s[0,2]} - #{s[2,2]}:#{s[4,2]}:#{s[6,2]}"  

irb(main):001:0> "%s - %s:%s:%s"%"20134859".unpack('a2'*4) => "20 - 13:48:59" 

or scan borrowed digitalross

irb(main):002:0> "%s - %s:%s:%s"%"20134859".scan(/../) => "20 - 13:48:59" 

Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -