ruby - Parse hours from string with space delimiter -
i have file strings contain dates in heading, stuff such 2017-03-06 092328 - iphone - music show - street performance, while walking dog.m4a
i parse date our of string, because need print in podcast friendly format.
i'm able parse out date, reason time component refuses parsed out :)
date.strptime("2017-03-06 092328", "%y-%m-%d %h%m%s").strftime(%y-%m-%d %h%m%s) expected output:
"2017-03-06 092328" actual output
"2017-03-06 000000"
your problem date (what surprise!) date, in, "not time, date".
require 'time' time.strptime("2017-03-06 092328", "%y-%m-%d %h%m%s").strftime("%y-%m-%d %h:%m:%s") #=> "2017-03-06 09:23:28" to fair :
- the documentation of
time#strptimementions it's based ondate#strptime date._parse("2017-03-06 09:23:28")happily return{:hour=>9, :min=>23, :sec=>28, :year=>2017, :mon=>3, :mday=>6}
if find confusing time object has date , time date has date, use datetime.
Comments
Post a Comment