I have the string (actually it's a date and time) like this "20120207080000".
Is there any option to split the given string using any pattern matching technique or anything else?
i.e I need the output like this
output = ["2012", "02", "07", "08", "00", "00"]
Otherwise is it possible to convert the given string into date/time object?.
ruby version: 1.8.7
"20120207080000".unpack('A4A2A2A2A2A2') #=> ["2012", "02", "07", "08", "00", "00"]
Get a DateTime object like this:
require 'date'
DateTime.strptime('20120207080000', '%Y%m%d%H%M%S')
Please take care that you are using the right order of elements. I was just guessing.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With