import java.sql.Time; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; import org.mvel.util.ThisLiteral; public class DateTools { public static boolean timeeqtime(String ta, String tb) { boolean flag = false; try { String fmt = ""; // 譬如要format为yyyyMM-dd fmt = "yyyy-MM-dd"; SimpleDateFormat sdf = new SimpleDateFormat(fmt); // Date date = new Date(); // String dateStr = sdf.format(date); // System. out.println(dateStr); Date tta = sdf.parse(ta); Date ttb = sdf.parse(tb); flag = (tta.getTime() == ttb.getTime()); } catch (ParseException e) { e.printStackTrace(); } return flag; } public static Date getDate(String str) { Date d = null; if (str == null || str.equals("")) { return null; } else { DateFormat format = new SimpleDateFormat("yyyy-MM-dd"); try { d = format.parse(str); } catch (Exception e) { e.printStackTrace(); } } return d; } public static String getDateTime() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); return sdf.format(new Date()); } public static String getDateTimeSSS() { SimpleDateFormat sdf = new SimpleDateFormat("yy-MM-dd HH:mm:ss:SSS"); try { Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } return sdf.format(new Date()); } public static String getDateXXX() { SimpleDateFormat sdf = new SimpleDateFormat("yyMMdd"); return sdf.format(new Date()); } public static String getDateTimeString() { return getDateTime().trim().replace("-","").replace(" ","").replace(":",""); } public static String getDateTimeStringSSS() { return getDateTimeSSS().trim().replace("-","").replace(" ","").replace(":",""); } }
时间: 2024-10-29 19:07:29