Need to Get the current DateTime in the Talend Studio?
46,037
You can use routine function TalendDate.parseDate
to convert a String
to a Date
.
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", yourStringData);
If you want the current datetime:
TalendDate.parseDate("yyyy-MM-dd HH:mm:ss", TalendDate.getDate("yyyy-MM-dd HH:mm:ss"));
But this makes no sense.
Parsedate function is prepared to receive a string and convert it to aDate
object. Date
objects have it's own format, so you don't have to care how is stored, you need to change the Date
format in the moment you show it, but not when you store it:
// this will produce a correct Date Object to store in your Date field
Date currentDate = TalendDate.getCurrentDate();
When you need to show/print it use SimpleDateFormat
for example if you want to show 2015-07-05 16:00:00 you must do like this:
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss);
System.out.println("My date formatted is: " + sdf.format(currentDate ));
Author by
Rajesh kannan
Updated on November 23, 2020Comments
-
Rajesh kannan over 3 years
I am working the Talend studio tool for data migration. Now I want to set the Current DateTime in the Date field. I get the DateTime from this code
TalendDate.getDate("yyyy-MM-dd HH:mm:ss")
but it returns String type data. But I needDate
type to insert.Is there any String to date (Sample insert is like this:1999-12-13 16:14:48
) conversion is in the Talend Studio. -
Rajesh kannan about 9 yearsTalendDate.parseDate("yyyy-MM-dd HH:mm:ss",TalendDate.getDate("yyyy-MM-dd HH:mm:ss"))Shall I use Like this code. Mr.Jordi
-
Rajesh kannan about 9 yearsI want to insert the current date and time like this format "yyyy-MM-dd HH:mm:ss".So shall I use this TalendDate.parseDate("yyyy-MM-dd HH:mm:ss",TalendDate.getDate("yyyy-MM-dd HH:mm:ss")). @Jordi Castilla
-
Jordi Castilla about 9 yearsread my updated answer, you are missing important things, hope it clarifies