public static String formatDateToString(long date) { SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS"); return formatter.format(date); } public String formatDate(Date date){ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return formatter.format(date); } //时间戳的格式化,当前时间往前推7天的时间戳:new Date().getTime()-7*24*3600*1000; public String formatDate(long date){ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); return formatter.format(date); } public long formatDate(String date){ SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); Date d = null; try { d = formatter.parse(date); } catch (ParseException e) { e.printStackTrace(); } return d.getTime(); } //相除的两个数,在JAVA中,应该用double类型的,保留两位小数点 public double decimalFormat(double f){ DecimalFormat decimalFormat=new DecimalFormat(".00"); return Double.valueOf(decimalFormat.format(f)); } public double decimalFormat(long a, long b){ DecimalFormat decimalFormat=new DecimalFormat(".00"); return Double.valueOf(decimalFormat.format((double)a/b)); }