cy
2022-06-21 129904537f66509f97b285e7eb4f42b3dc349dd0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package cn.ksource.core.component;
 
import java.util.List;
 
import org.apache.commons.lang.StringUtils;
 
import cn.ksource.core.util.ConvertUtil;
import cn.ksource.core.util.DateUtil;
import freemarker.template.TemplateMethodModel;
import freemarker.template.TemplateModelException;
 
public class Format implements TemplateMethodModel {
 
    //24小时:yyyy-MM-dd HH:mm:ss 
    //12小时:yyyy-MM-dd hh:mm:ss
    
    @Override
    public Object exec(List list) throws TemplateModelException {
        String arg = "";
        if (list.size() == 0) {
            return null;
        }
        String date = ConvertUtil.obj2Str(list.get(0));
        if (StringUtils.isBlank(date)) {
            return null;
        }
        if (list.size() == 1) {
            arg = "yyyy-MM-dd";
        } 
        if (list.size() == 2) {
            arg = ConvertUtil.obj2Str(list.get(1));
        } 
        
        return DateUtil.format(arg, date);
    }
 
}