package com.sinosoft.cm.common; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.List; import nl.justobjects.pushlet.util.Sys; /** * 时间格式转换类 * @author Administrator * */ public class DateUtil { private static SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); private static SimpleDateFormat formatterTime = new SimpleDateFormat("HH:mm"); public DateUtil() { } /** * util格式date想sql格式date转换 * @param date * @return */ public static java.sql.Date toSqlDate(java.util.Date date){ return new java.sql.Date(date.getTime()); } /** * sql格式date向util格式date转换 * @param date * @return */ public static java.util.Date toUtildate(java.sql.Date date){ return new java.util.Date(date.getTime()); } /** * sql格式date转换为字符串 * @param date * @return */ public static String toString(java.sql.Date date){ return toString(toUtildate(date)); } /** * 字符串转换为sql格式date * @param dateString * @return */ public static java.sql.Date toSqlDate(String dateString){ return toSqlDate(toData(dateString)); } /** * util格式date转换为字符串 * @param date * @return */ public static String toString(java.util.Date date){ return formatter.format(date); } public static String toTimeString(java.util.Date date){ return formatterTime.format(date); } /** * 字符串转换为util格式date * @param dateString * @return */ public static java.util.Date toData(String dateString){ try { return formatter.parse(dateString); } catch (ParseException e) { e.printStackTrace(); } return null; } /** * 获取间隔时间集合 * @param dateTime * @param n * @param timeInterval * @return */ public static List getUitlDates(String dateTime,int n,int timeInterval){ List dateString=new ArrayList(); for(int index=0;index dateStringToDateString(List list){ List dateList=new ArrayList(); for(String item : list){ Date temDate=DateUtil.toData(item); dateList.add(formatterTime.format(temDate)); } return dateList; } /* public static void main(String[] args) { System.out.println( DateUtil.dateStringToDateString(DateUtil.getUitlDates("2012-12-12 13:12:12", 10, 3))); }*/ }