ruby - How do I split a string into separate components to parse into a DateTime? -


this question has answer here:

i have string looks like:

20130518134721 yyyymmddhhmmss 

this time of day. knowing format of string, , knowing year padded 4 digits , others padded 2 digits, how can split string can extract specific information such month, or hour?

you can use datetime.strptime convert string datetime object. can like:

date = datetime.strptime("20130518134721", "%y%m%d%h%m%s") → datetime 

after that, can access different methods of date object in ruby hour or mon.

date.hour                #=> 13 date.mon #=> 5 

also, remember require 'date' use datetime object.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -