Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to Get the current DateTime in the Talend Studio?

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 need Date 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.

like image 894
Rajesh kannan Avatar asked May 07 '15 13:05

Rajesh kannan


People also ask

How can I get current year in Talend?

If you want the current datetime: TalendDate. parseDate("yyyy-MM-dd HH:mm:ss", TalendDate. getDate("yyyy-MM-dd HH:mm:ss"));

How can I get current month in Talend?

System. out. println("Current Month: " + globalMap. get("current_month"));

What is the default date pattern in Talend Open Studio?

In talend what is the fixed pattern of date? By default the date pattern is dd-MM-yyyy.


1 Answers

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 a Date 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 ));
like image 178
Jordi Castilla Avatar answered Sep 28 '22 00:09

Jordi Castilla