TimeUtil.java 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 long getNowLong() {
  12. return System.currentTimeMillis();
  13. }
  14. public static String getNowString() {
  15. return System.currentTimeMillis()+"";
  16. }
  17. public static Timestamp getNowForMysql() {
  18. return new Timestamp(System.currentTimeMillis());
  19. }
  20. public static long zeroOfToday() {
  21. return System.currentTimeMillis() / (1000 * 3600 * 24) * (1000 * 3600 * 24) - TimeZone.getDefault().getRawOffset();
  22. }
  23. //获取时间类型格式转化
  24. public static Integer getRq(Date date, int index){
  25. SimpleDateFormat sdf = new SimpleDateFormat(dateFmtArr[index]);
  26. if(date == null){
  27. date = new Date();
  28. }
  29. return Integer.valueOf(sdf.format(date));
  30. }
  31. }