I have a requirement like, the date difference should be calculated from an input date and the current date in Talend java platform. In that case I can use TalendDate.diffDate(date1, date2) : long method, where date1 and date2 are of type Date
So I can invoke that method inside my own method,
public static long findDateDiff(Date date2){
Date date1 = new Date(); //current date of format Fri Feb 23 09:37:33 IST 2018
// date2 format is 'dd/MM/yyyy'
long diff = TalendDate.diffDate(date1,date2);
return diff
}
Here, the parameter date2 is of type Date and format 'dd/MM/yyyy'. But when I get the current date, it is of different format, so I have a trouble in passing the dates with different formats.
How can I convert the current date format to 'dd/MM/yyyy' into the same variable date2?
Date date1 = new Date(); //current date of format Fri Feb 23 09:37:33 IST 2018 String sDate = new SimpleDateFormat.format(date1); //returns only String format
If I use the above method SimpleDateFormat.format(Date), it returns a String value, and how can I pass the value to diffDate(date1, date2) where both the parameter types are Date?
So I just need to convert the current date, into a specified format and store the result into the same Date variable, rather than getting it as a String.
Please help me resolve this issue. Thanks in advance.