TimeUtil.java 937 B

1234567891011121314151617181920212223242526272829303132
  1. package api.common.util;
  2. import java.sql.Timestamp;
  3. import java.text.SimpleDateFormat;
  4. import java.util.Date;
  5. import java.util.TimeZone;
  6. public class TimeUtil {
  7. private static String[] dateFmtArr= new String[]{"yyyyMMdd", "yyyy-MM-dd HH:mm:ss","yyyy-MM-dd","HHmmssSS"};
  8. public static long getNow() {
  9. return System.currentTimeMillis();
  10. }
  11. public static Timestamp getNowForMysql() {
  12. return new Timestamp(System.currentTimeMillis());
  13. }
  14. public static long zeroOfToday() {
  15. return System.currentTimeMillis() / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
  16. }
  17. //获取时间类型格式转化
  18. public static Integer getRq(Date date, int index){
  19. SimpleDateFormat sdf = new SimpleDateFormat(dateFmtArr[index]);
  20. if(date == null){
  21. date = new Date();
  22. }
  23. return Integer.valueOf(sdf.format(date));
  24. }
  25. }