package com.qiyuan.util; import java.text.SimpleDateFormat; import java.util.Date; public class orderCode { //订单编号前缀 public static final String PREFIX = "DD"; //订单编号后缀(核心部分) private static long code; // 生成订单编号 public static synchronized String getOrderCode() { code++; String str = new SimpleDateFormat("yyyyMMddHHmmss").format(new Date()); long m = Long.parseLong((str)) * 10000; m += code; return PREFIX + m; } public static void main(String[] args) { System.out.println(orderCode.getOrderCode()); } }
原文地址:https://www.cnblogs.com/javahr/p/8321352.html
时间: 2024-10-10 15:02:47