java时间格式化转换

来源:互联网 发布:赛尔网络集美大学 编辑:程序博客网 时间:2024/06/11 11:54
/** * 日期格式转换 Date返回Date * @param date * @param dateFormat * @return */public static Date dateToDate(Date date,String dateFormat){if(date==null){return null;}SimpleDateFormat format = new SimpleDateFormat(dateFormat);ParsePosition pos = new ParsePosition(0);Date strtodate = format.parse( format.format(date).toString(),pos);return strtodate;    }/** * 日期格式转换 String返回Date * @param date * @param dateFormat * @return */public static Date strToDate(String date,String dateFormat){if(date==null){return null;}SimpleDateFormat format = new SimpleDateFormat(dateFormat);ParsePosition pos = new ParsePosition(0);Date strtodate = format.parse(date,pos);return strtodate;}/** * 日期格式转换 Date返回String * @param date * @param dateFormat * @return */public static String dateToString(Date date,String dateFormat){        if(date==null){return null;}SimpleDateFormat format = new SimpleDateFormat(dateFormat);//ParsePosition pos = new ParsePosition(0);return format.format(date).toString();}/** * 日期格式转换 String返回String  * @param date * @param dateFormat * @return */public static String strToStr(String date,String dateFormat){if(date==null){return null;}SimpleDateFormat format = new SimpleDateFormat(dateFormat);ParsePosition pos = new ParsePosition(0);Date strtodate = format.parse(date,pos);return format.format(strtodate).toString();}

原创粉丝点击