时间格式生成序列【主键】
2014-12-24 19:47
381 查看
时间格式生成序列【主键】
public class GenerateSequenceUtil { /** .log */ // private static final Logger logger = Logger.getLogger(GenerateSequenceUtil.class); /** The FieldPosition. */ private static final FieldPosition HELPER_POSITION = new FieldPosition(0); /** This Format for format the data to special format. */ private final static Format dateFormat = new SimpleDateFormat("MMddHHmmssS"); /** This Format for format the number to special format. */ private final static NumberFormat numberFormat = new DecimalFormat("0000"); /** This int is the sequence number ,the default value is 0. */ private static int seq = 0; private static final int MAX = 9999; /** * 时间格式生成序列 * @return String */ public static synchronized String generateSequenceNo() { Calendar rightNow = Calendar.getInstance(); StringBuffer sb = new StringBuffer(); dateFormat.format(rightNow.getTime(), sb, HELPER_POSITION); numberFormat.format(seq, sb, HELPER_POSITION); if (seq == MAX) { seq = 0; } else { seq++; } // logger.info("THE SQUENCE IS :" + sb.toString()); return sb.toString(); } public static void main(String[] args) { System.out.println(GenerateSequenceUtil.generateSequenceNo()); } }
相关文章推荐
- sqlSever 存储过程 中 创建 事务(增删改操作),唯一的主键自动生成 (格式:自定义字母+时间+五位数字,例如:S2014103010001)
- Windows 驱动:获取系统当前时间,生成格式字符串
- oracle结合序列和触发器生成表的主键
- ibatis主键生成方式 用序列实现自动增长 查询方式
- Android:获取当前系统时间生成日期格式
- 通过表的生成主键序列(seqence)
- C#简单生成订单编号--通过精确到毫秒的时间格式
- IIS7.5真变态,服务器时间格式导致不生成WebResource.axd
- Windows 驱动:获取系统当前时间,生成格式字符串
- 琪露诺也能看懂的Oracle 主键值的序列自动生成与分配
- SpringSide 3.1.2的主键id序列值如何生成
- 简单的SQl时间序列生成,每次时间间隔10分钟。
- Oracle建表,建序列,建触发器,自动生成唯一主键
- spring jdbctemplate插入blob,clob并且返回生成的序列主键
- C# DateTime.ToString生成不同语言的时间格式
- 第八课 从序列中生成主键
- 基于Oracle,采用JDBC、Hibernate不同方式实现自定义序列主键生成
- etmvc中生成JsonView的时间格式问题处理
- 生成时间格式加随机四位数的数字组合
- JAVA中通过时间格式来生成唯一的文件名