Your problem is the typical use case for the functions
strptime for parsing the textual date and and
strftime for formatting the output.
The code for strptime can be found also
here.
The rest is some code writing. But be aware: you must detect yourself which pattern to use. Write some tests for check the robustness of your solution.