📄 dateconverter.java
字号:
package com.itcast.utils;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.apache.commons.beanutils.Converter;
public class DateConverter implements Converter {
@SuppressWarnings("unchecked")
public Object convert(Class clazz, Object value) {
if(value==null || "".equals((String)value)) return null;
if(value instanceof Date) return value;
DateFormat convert = new SimpleDateFormat("yyyy-MM-dd");
try {
return convert.parse((String) value);
} catch (ParseException e) {
DateFormat convert2 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
return convert2.parse((String) value);
} catch (ParseException e1) {}
}
return null;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -