生成订单号(利用时间转化)
/**
* 订单号生成 20200718112629527
*/
public static String nextItemNo(){
LocalDateTime dateTime = LocalDateTime.now();
return DateLiuUtil.getOtherFormatterLocalDateTime(dateTime);
}
PS:LocalDateTime源码
/**
* Obtains the current date-time from the system clock in the default time-zone.
* <p>
* This will query the {@link Clock#systemDefaultZone() system clock} in the default
* time-zone to obtain the current date-time.
* <p>
* Using this method will prevent the ability to use an alternate clock for testing
* because the clock is hard-coded.
*
* @return the current date-time using the system clock and default time-zone, not null
*/
public static LocalDateTime now() {
return now(Clock.systemDefaultZone());
}
PS:getOtherFormatterLocalDateTime源码
/**
* 格式化日期格式 yyyy-MM-dd HH:mm:ss
*
* @param localDateTime 传入需要格式化的日期
* @return 返回格式化后的日期字符串
*/
public static String getOtherFormatterLocalDateTime(LocalDateTime localDateTime) {
DateTimeFormatter dateTimeFormatter = getDateTimeFormatter(DEFAULT_PATTERN_DATETIME_SIMPLE_FULL);
return getLocalDateTimeFormat(localDateTime, dateTimeFormatter);
}