I have this string s that is formatted in this way. I want to turn it into a Time object.
Here is my attempt at doing this and making it readable.
s = "15081992"
n = { :year=> s[4..7], :month=> s[2..3], :day=> s[0..1] }
newtime = Time.mktime( n[:year], n[:month], n[:day] )
# 1992-08-15 00:00:00 -0400
It works, but I’m seeking any suggestion or feedback on how to write this in a better way to achieve the same result or is this pretty much it?
1 Answer