JAVA中时间与字符串的相互转换(工具类)

来源:互联网 发布:网页.js是什么文件 编辑:程序博客网 时间:2024/06/04 18:48
<span style="font-size:24px;">//model为字符串的时间格式,如"<span style="font-family: arial; line-height: 20.02px;">yy-MM-dd</span><span style="font-family: arial; line-height: 20.02px;"> HH:mm:ss"</span></span>
<span style="font-size:24px;">public class DateFormat {    public static Date StringToDate(String date,String model){//字符串转时间        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(model);        Date date1=null;        try {            date1=simpleDateFormat.parse(date);        } catch (ParseException e) {            e.printStackTrace();        }        return date1;    }    public static String DateToString(Date date,String model){//时间转字符串        SimpleDateFormat simpleDateFormat=new SimpleDateFormat(model);        return simpleDateFormat.format(date);    }}</span>

0 0