• JEECG中修改时间相关自定义定时器


    JEECG中使用,如下:

    	@InitBinder
    	public void initBinder(ServletRequestDataBinder binder) {
            
    		binder.registerCustomEditor(Date.class, new DateConvertEditor());
    	}
    

    其中的DateConvertEditor类是JEECG中用于将日期进行转换的类。其主要代码如下:

    	private SimpleDateFormat datetimeFormat = new SimpleDateFormat(
    			"yyyy-MM-dd HH:mm:ss");
    	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");	
    	public void setAsText(String text) throws IllegalArgumentException {
    		if (StringUtils.hasText(text)) {
    			try {
    				if (text.indexOf(":") == -1 && text.length() == 10) {
    					setValue(this.dateFormat.parse(text));
    				} else if (text.indexOf(":") > 0 && text.length() == 19) {
    					setValue(this.datetimeFormat.parse(text));
    				} else if (text.indexOf(":") > 0 && text.length() == 21) {
    					text = text.replace(".0", "");
    					setValue(this.datetimeFormat.parse(text));
    
    				} else if (text.indexOf(":") > 0 && text.indexOf(".") > 0 && text.length() > 21) {
    					text = text.substring(0, text.indexOf("."));
    					setValue(this.datetimeFormat.parse(text));
    				}else {
    					throw new IllegalArgumentException(
    							"Could not parse date, date format is error ");
    				}
    				...
    

    可以看出,其中的datatimeFormat用于处理"yyyy-MM-dd HH:mm:ss"格式的字符串,而dateFormat用于处理"yyyy-MM-dd"

  • 相关阅读:
    新的思考方式
    我在干售后!
    设计制造嵌入式系统
    镶嵌在系统中的系统
    苏黄永郦的第六周读书报告
    苏黄永郦的第五周读书报告
    苏黄永郦的第四周读书报告
    苏黄永郦的第三周读书报告
    1051 最大子矩阵和
    1065 最小正子段和
  • 原文地址:https://www.cnblogs.com/Jeely/p/12613322.html
Copyright © 2020-2023  润新知