DateUtils.java 975 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package cn.com.ty.lift.common.utils;
  2. import cn.hutool.core.date.BetweenFormater;
  3. import cn.hutool.core.date.DateUtil;
  4. import java.time.LocalDate;
  5. import java.time.ZoneId;
  6. import java.time.ZonedDateTime;
  7. import java.util.Date;
  8. public class DateUtils {
  9. /**
  10. * LocalDate转Date
  11. *
  12. * @param localDate
  13. * @return
  14. */
  15. public static Date localDate2Date(LocalDate localDate) {
  16. if (null == localDate) {
  17. return null;
  18. }
  19. ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.systemDefault());
  20. return Date.from(zonedDateTime.toInstant());
  21. }
  22. /**
  23. * 生成当前时间的年月日时分秒毫秒微秒
  24. *
  25. * @return
  26. */
  27. public static String generateCode() {
  28. return DateUtil.format(new Date(), "yyyyMMddHHmmssSSS");
  29. }
  30. public static void main(String[] args) {
  31. System.out.println(DateUtil.formatBetween(1212112121, BetweenFormater.Level.SECOND));
  32. }
  33. }