I am building a text localisation library using only packages beginning with Java. or Javax. ("Standard Java API's").
The ultimate goal of the library is to read a text file, identify and change the dates and currencies from the sourceFormat (the format from the text file) which will be declared by the user for ease of formatting, to the outputFormat (again declared by the user).
The outputFormats are then inserted into a new string in the correct positions and then saved to a new text file.
The only piece of "the puzzle" left to solve is for formatting/localising the dates.
I currently have various methods coded that will extract these 3 variables (instantiated below with potential examples):
String outputFormat = "dd/MM/yyyy"; // UK Format
String sourceFormat = "yyyy-MM-dd"; // German Format
String dateFromText = "26/05/2001";
After reading around I cannot find any way to do this for the dates with ease in Java.... (Maybe I'm missing something??)
So my question is what would be the easiest way to code this? (By easiest I mean this quickest for me to implement and get the code working. Not worried at this point about the efficiency of the code).
I found this code on SO for a similar problem in C#: How to convert any date format to yyyy-MM-dd
string DateString = "11/12/2009";
IFormatProvider culture = new CultureInfo("en-US", true);
DateTime dateVal = DateTime.ParseExact(DateString, "yyyy-MM-dd", culture);
Something like this but for Java would be perfect.
Thanks!