package com.infohold.smallpay.map.util.codebuild;
import org.apache.log4j.Logger;
import java.io.File;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
/**
* Created by wlh on 2017/12/14.
*/
public class CodeUtil {
private static int width=4; //位数
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
private static DecimalFormat df = null;
private static final Logger log=Logger.getLogger(CodeUtil.class);
public static synchronized String getNumber() {
String result = null;
try {
File file=new File("SNumber.dat");
char[] chs = new char[width];
for (int i = 0; i < width; i++) {
chs[i] = '0';
}
df = new DecimalFormat(new String(chs));
Date current = new Date();
String date = sdf.format(current);
int num = 1;
if (file.exists()) {
List< String > list = FileUtil.readList(file);
String[] data = list.get(0).split(",");
if (date.equals(data[0])) {
num = Integer.parseInt(data[1]);
}
}
FileUtil.rewrite(file, date + "," + (num + 1));
result = sdf.format(current) + df.format(num);
} catch (Exception e) {
log.error("生成id有误");
e.printStackTrace();
}
return result;
}
}
生成以日期开头,加4位数字,每次加1的工具类.如:201712140001
4星 · 超过85%的资源 需积分: 48 137 浏览量
2017-12-14
17:27:17
上传
评论 1
收藏 1KB ZIP 举报
-hua-
- 粉丝: 18
- 资源: 5
最新资源
- 单片机其应用技术(C语言版)考试题二.doc
- 狗鼻子检测数据集VOC+YOLO格式3099张1类别.zip
- .arch4位0.36寸共阳数码管(带时钟点、不带小数点)引脚图-请忽略图中尺寸.jpg
- 基于单片机430采集电容极板的电容值,并通过蓝牙传输到安卓端,安卓端负责接收蓝牙数据及可视化显示(OpenGL ES)
- 2,标准例程-HAL库版本.zip
- NVD和CNNVD软件漏洞数据集,漏洞文本预处理,训练算法模型进行漏洞分类.zip
- java 毕业设计之实现的汽车租赁管理系统
- MongoDB数据库及基本操作.txt
- 毕业设计基于Python时空图卷积(ST-GCN)的骨骼动作识别源码(高分项目).zip
- 基于C++面向软件安全的污点数据检测系统源码.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈