How to do velocity concatenation?
10,585
There are several mistake in your code DateTool dateformat wrong Your format should be dd-MM-yyyy
not ddMMyyyy
.
Velocity string concatenation we need to use always variables and set in velocity always #set
I have added this map
contextMap.put("dateTool",new DateTool());
contextMap.put("date_curr1","14");
contextMap.put("month_curr1","06");
contextMap.put("year_curr1","2017");
And velocity file
#set($concat ="-")
#set( $str = "$date_curr1$concat$month_curr1$concat$year_curr1 ")
$str
#set( $dateFormated = $dateTool.toDate("dd-MM-yyyy",$str))
$dateFormated
Output
14-06-2017
Author by
anurag hn
Updated on June 27, 2022Comments
-
anurag hn almost 2 years
I have three variables that are extracted from date: date, month and year separately. I want to concatenate them into one variable and then convert into a date format. I am trying like this
#set( $str = "$date_curr1$month_curr1$year_curr1" ) #set( $dateFormated = $dateTool.toDate("ddMMyyyy", $str))