I am trying to create a generic class for date conversion in DataFlow
with below code:
class DateConversion
{
private static final StringBuffer appendable = null;
public String dateConversion(String InputdateFormat, String OutputdateFormat, String date1) throws ParseException
{
DateFormat CurrentDateFormat = new SimpleDateFormat(InputdateFormat);
DateFormat RequireDateFormat = new SimpleDateFormat(OutputdateFormat);
Date theDate = CurrentDateFormat.parse(date1);
return theDate.toString();
}
}
If I pass date input date format date in YYYY-MM-DD HH:MM:SS format then I am able to load the data successfully in datetime/timestamp column in BigQuery using DF job. If I pass input date format in different formats(like YYMMDD or MMDDYY) then program is loading incorrect date or failing due to incorrect date format. Please help me to make above code generic.