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.
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"));
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 ));