Without using a third party module, what steps would I need to take to convert this:
<<"Mon, 17 Feb 2014 11:07:53 GMT">>
Into this?:
[17, 2, 2014, 10, 07, 53]
Most of the answers I've Googled suggest using a library. So far, I suspect I'd get somewhere by pattern matching the formatted date string.
Something like:
<<_:5/binary, Date:2/binary>> = <<"Mon, 17 Feb 2014 11:07:53 GMT">>...
Which I think should produce the following 'match'
Date = 17...
That's based on an idea found here - https://groups.google.com/forum/#!topic/erlang-programming/OpXSqt3U86c - Is this a good approach?
Are there any BIF's or modules that can help with this? And furthermore, how would I convert/map "Feb" to an integer?
Let's try that in the shell:
Right, we need to match the rest of the binary at the same time:
So now
Date
is a binary containing the bytes for the ASCII digits 1 and 7. We can convert that to a number withbinary_to_integer
:As for the conversion of month names to integers, the usual way to do something like that is with a function:
You may use tempo library for datetime formatting and parsing.
Why suffering? Why not third party module?
I am use erlware_commons
ec_date:parse("Mon, 17 Feb 2014 11:07:53 GMT").
the output is: