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
Post a Comment