Answer the question
In order to leave comments, you need to log in
How to automatically detect date/time format?
The problem is that there are huge text documents that need to be read and calculated time.
If there is always 1 constant format, then after adding a sheet or something like that, it would look like this:
SimpleDateFormat format = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
ArrayList<String> obj = new ArrayList<String>();
obj.add("06.03.2016 09:00:00");
obj.add("06.03.2016 17:45:00");
obj.add("06.03.2016 23:51:12");
obj.add("07.03.2016 00:55:33");
String format = "06.03.2016 09:00:00";
format = DetermineFormat(String format){
if (format.... ????????)
return dd.MM.yyyy HH:mm:ss
}
Answer the question
In order to leave comments, you need to log in
Since I still didn’t find the answer, I did it all the same with a crutch through checking possible formats
// list of a different format types. If you need new one, just past it here.
private static List<SimpleDateFormat> dateFormats = new ArrayList<SimpleDateFormat>() {{
add(new SimpleDateFormat("MM/dd/yyyy hh:mm:ss")); //US
add(new SimpleDateFormat("dd/MM/yyyy HH:mm:ss")); //EU
add(new SimpleDateFormat("MM.dd.yyyy hh:mm:ss")); //US
add(new SimpleDateFormat("dd.MM.yyyy HH:mm:ss")); //EU
add(new SimpleDateFormat("MM-dd-yyyy hh:mm:ss")); //US
add(new SimpleDateFormat("dd-MM-yyyy HH:mm:ss")); //EU
}
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question