需要在Talend Studio中获取当前的DateTime吗?

Raj*_*nan 4 java string datetime date talend

我正在使用Talend工作室工具进行数据迁移.现在我想在Date字段中设置Current DateTime.我从这段代码中获取DateTime,TalendDate.getDate("yyyy-MM-dd HH:mm:ss")但它返回String类型数据.但我需要Date输入类型.是否有任何String到目前为止(示例插入是这样:) 1999-12-13 16:14:48转换是在Talend Studio中.

Jor*_*lla 14

您可以使用例程函数TalendDate.parseDate将a转换String为a Date.

TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", yourStringData);
Run Code Online (Sandbox Code Playgroud)

如果你想要当前的日期时间:

TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", TalendDate.getDate("yyyy-MM-dd HH:mm:ss"));
Run Code Online (Sandbox Code Playgroud)

但这毫无意义.

Parsedate函数准备接收字符串并将其转换为Date对象.Date对象具有自己的格式,因此您不必关心如何存储,您需要在显示时更改Date格式,但不能在存储时更改格式:

// this will produce a correct Date Object to store in your Date field
Date currentDate = TalendDate.getCurrentDate();  
Run Code Online (Sandbox Code Playgroud)

当您需要显示/打印它时SimpleDateFormat,例如,如果您想要显示2015-07-05 16:00:00,您必须这样做:

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss);
System.out.println("My date formatted is: " + sdf.format(currentDate ));
Run Code Online (Sandbox Code Playgroud)