Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/string/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 需要在Talend Studio中获取当前日期时间吗?_Java_String_Date_Datetime_Talend - Fatal编程技术网

Java 需要在Talend Studio中获取当前日期时间吗?

Java 需要在Talend Studio中获取当前日期时间吗?,java,string,date,datetime,talend,Java,String,Date,Datetime,Talend,我正在使用Talend studio工具进行数据迁移。现在我想在日期字段中设置当前日期时间。 我从这个代码TalendDate.getDate(“yyyy-MM-dd HH:MM:ss”)中获取日期时间,但它返回字符串类型的数据。但是我需要插入Date类型。到目前为止是否有任何字符串(插入示例如下:1999-12-13 16:14:48)转换在Talend Studio中 您可以使用例程函数TalendDate.parseDate将字符串转换为日期 TalendDate.parseDate("y

我正在使用Talend studio工具进行数据迁移。现在我想在日期字段中设置当前日期时间。
我从这个代码
TalendDate.getDate(“yyyy-MM-dd HH:MM:ss”)
中获取日期时间,但它返回字符串类型的数据。但是我需要插入
Date
类型。到目前为止是否有任何字符串(插入示例如下:
1999-12-13 16:14:48
)转换在Talend Studio中

您可以使用例程函数
TalendDate.parseDate
字符串
转换为
日期

TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", yourStringData);
如果需要当前日期时间:

TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", TalendDate.getDate("yyyy-MM-dd HH:mm:ss"));
但这毫无意义。Parsedate函数准备接收字符串并将其转换为
Date
对象<代码>日期对象有它自己的格式,因此您不必关心如何存储,您需要在显示日期时更改日期格式,而不是在存储日期时更改:

// this will produce a correct Date Object to store in your Date field
Date currentDate = TalendDate.getCurrentDate();  
当您需要显示/打印它时,例如,如果您想显示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 ));

在java中使用DateFormat非常简单

public static void convert(String inputDate) throws ParseException {

        DateFormat format = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss");
        Date d = format.parse(inputDate); // example 1999-12-13 16:14:48
                System.out.println(d);
    }

TalendDate.parseDate(“yyyy-MM-dd-HH:MM:ss”,TalendDate.getDate(“yyy-MM-dd-HH:MM:ss”))应该像这样使用代码。JordiI先生想像这样插入当前日期和时间格式“yyyy-MM-dd HH:MM:ss”。那么我应该使用这个TalendDate.parseDate(“yyy-MM-dd HH:MM:ss”,TalendDate.getDate(“yyyy-MM-dd HH:MM:ss”))@Jordi Castillard我的最新答案,你错过了重要的事情,希望澄清