DateUtils.java 885 B

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