如何做速度连接?

问题描述 投票:0回答:1

我有三个从日期中提取的变量:日期,月份和年份。我想将它们连接成一个变量,然后转换为日期格式。我这样想

#set( $str = "$date_curr1$month_curr1$year_curr1" )
#set( $dateFormated = $dateTool.toDate("ddMMyyyy", $str))
apache velocity converters
1个回答
1
投票

您的代码中有几个错误DateTool dateformat错误您的格式应该是dd-MM-yyyy而不是ddMMyyyy

速度字符串连接我们需要始终使用变量并设置在速度总是#set我添加了这个地图

contextMap.put("dateTool",new DateTool());
contextMap.put("date_curr1","14");
contextMap.put("month_curr1","06");
contextMap.put("year_curr1","2017");

和速度文件

#set($concat ="-")
#set( $str = "$date_curr1$concat$month_curr1$concat$year_curr1 ")
$str
#set( $dateFormated = $dateTool.toDate("dd-MM-yyyy",$str))
$dateFormated

产量

14-06-2017 
© www.soinside.com 2019 - 2024. All rights reserved.