I’ve got date and time in separate fields, in yyyyMMdd and HHmmss formats respectively. To parse them I think to construct a yyyy-MM-ddTHH:mm:ss string and feed this to joda-time constructor. So I am looking to get 1-st 4 digits, then 2 digits starting from the index 5, etc. How to achieve this? List.fromString(String) (which I found here) seems to be broken.
I’ve got date and time in separate fields, in yyyyMMdd and HHmmss formats respectively.
Share
Just use the
substring()method on the string. Note that Scala strings behave like Java strings (with some extra methods), so anything that’s injava.lang.Stringcan also be used on Scala strings.(Note that the arguments are not length and starting index, but starting index (inclusive) and ending index (exclusive)).
But if this is about parsing dates, why don’t you just use
java.text.SimpleDateFormat, like you would in Java?