zoukankan      html  css  js  c++  java
  • 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"

  • 相关阅读:
    mysql基础命令(一)
    vue组件之间的通信
    wepy的使用
    mockjs中的方法(三)
    每周散记 20181022
    api资源
    三七
    画中画 视频合成
    每周散记 20180910
    linux文件权限多一个+啥意思
  • 原文地址:https://www.cnblogs.com/zifeiy/p/9014258.html
Copyright © 2011-2022 走看看