package api.common.util; import java.sql.Timestamp; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class TimeUtil { private static String[] dateFmtArr= new String[]{"yyyyMMdd", "yyyy-MM-dd HH:mm:ss","yyyy-MM-dd","HHmmssSS"}; public static long getNow() { return System.currentTimeMillis(); } public static long getNowLong() { return System.currentTimeMillis(); } public static String getNowString() { return System.currentTimeMillis()+""; } public static Timestamp getNowForMysql() { return new Timestamp(System.currentTimeMillis()); } public static long zeroOfToday() { return System.currentTimeMillis() / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset(); } //获取时间类型格式转化 public static Integer getRq(Date date, int index){ SimpleDateFormat sdf = new SimpleDateFormat(dateFmtArr[index]); if(date == null){ date = new Date(); } return Integer.valueOf(sdf.format(date)); } }