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.
Asked
Active
Viewed 5.6k times
5

Jordi Castilla
- 26,609
- 8
- 70
- 109

Rajesh kannan
- 71
- 1
- 2
- 11
2 Answers
18
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 ));

Jordi Castilla
- 26,609
- 8
- 70
- 109
-
TalendDate.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 May 07 '15 at 13:36
-
I 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 – Rajesh kannan May 07 '15 at 13:45
-
read my updated answer, you are missing important things, hope it clarifies – Jordi Castilla May 07 '15 at 13:58
0
its very simple with the use of DateFormat in java
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);
}

kavi temre
- 1,321
- 2
- 14
- 21