首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

自定义日期跟字符串之间的类型转换器另附把字符串解析成日期的方法

2012-11-16 
自定义日期和字符串之间的类型转换器另附把字符串解析成日期的方法import java.text.ParseExceptionimpor

自定义日期和字符串之间的类型转换器另附把字符串解析成日期的方法

import java.text.ParseException;import java.text.SimpleDateFormat;import java.util.Date;import org.apache.commons.beanutils.locale.converters.DateLocaleConverter;public class Demo {public static void main(String[] args) {String strdate = "1990-12-32";/*SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");format.setLenient(false);try {Date date = format.parse(strdate);String localdate = format.format(date);System.out.println(localdate);} catch (ParseException e) {System.out.println("格式不对");}*///用这个类转换12-32时就会抛异常DateLocaleConverter dcl = new DateLocaleConverter();try {dcl.convert(strdate, "yyyy-MM-dd");} catch (Exception e) {System.out.println("格式不对");}}}

热点排行