无法在DataFlow Apache beam中创建通用日期转换类

时间:2022-01-30 14:57:35

I am trying to create a generic class for date conversion in DataFlow with below code:

我正在尝试使用以下代码在DataFlow中创建日期转换的泛型类:

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.

如果我以YYYY-MM-DD HH:MM:SS格式传递日期输入日期格式日期,那么我可以使用DF作业在BigQuery的datetime / timestamp列中成功加载数据。如果我以不同的格式(如YYMMDD或MMDDYY)传递输入日期格式,则程序正在加载错误的日期或由于日期格式不正确而失败。请帮我把上面的代码设为通用的。

1 个解决方案

#1


0  

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

如何使用SimpleDateFormat以多种格式解析日期

#1


0  

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

如何使用SimpleDateFormat以多种格式解析日期