I would like to be able to get the format string from a DateTime string.
e.g.
"2012-12-08 15:00:00" => "yyyy-MM
You can have a set of predefined formats and parse the date and see if it passes, then you can get the string format you are looking for.
Refer to the answer but its in java - How to get the given date string format(pattern) in java?