1

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.

pppery
  • 3,731
  • 22
  • 33
  • 46

1 Answers1

-1

So the issue is you need to support many different date formats? Perhaps something like this would help?

How to parse dates in multiple formats using SimpleDateFormat

Alex Amato
  • 1,685
  • 10
  • 15
  • SimpleDateFormat is not thread-safe so it would be a **bad idea** to use it in an [Embarrassigly parallel](https://en.wikipedia.org/wiki/Embarrassingly_parallel) environment – vdolez Sep 19 '18 at 09:26