时间对比、流水号计算、100%统计
来源:互联网 发布:excel如何数据分析 编辑:程序博客网 时间:2024/05/29 10:37
项目最近有个几以前没遇到的场景,记录下来,供以后查阅,有更好实现的盆友,忘多多分享。
时间对比
private static void diffTime() {DateFormat df = new SimpleDateFormat("yyyy-MM-dd");try {Date d1 = df.parse("2004-12-03");Date d2 = df.parse("2004-12-12");System.out.println(d2.before(d1));} catch (ParseException e) {//格式错误}}
通过Date方法的before和after方法判断
100%统计
private static double getAllFund(String govFund, String stateFund, String collectiveFund,String privateFund, String foreignFund, String otherFund) {double sum = add(govFund, stateFund);sum = add(Double.toString(sum), collectiveFund);sum = add(Double.toString(sum), privateFund);sum = add(Double.toString(sum), foreignFund);sum = add(Double.toString(sum), otherFund);return sum;} public static double add(String v1, String v2) { BigDecimal b1 = new BigDecimal(v1); BigDecimal b2 = new BigDecimal(v2); return b1.add(b2).doubleValue(); }
根据多个百分数统计,最后统计出总和,使用BigDecimal避免出现多为小数点的情况。
流水号计算
private static Calendar pre= null ;private static int index = 1;private static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");public static synchronized String getSerialNumber() {Calendar current = Calendar.getInstance();StringBuffer sb = new StringBuffer(sdf.format(current.getTime()));if (pre == null) {//刚进入pre = current;index = 1;sb.append("001");} else {//比较年月日,相同时加1int preYear=pre.get(Calendar.YEAR);//得到年int preMonth=pre.get(Calendar.MONTH)+1;//得到月,因为从0开始的,所以要加1int preDay=pre.get(Calendar.DAY_OF_MONTH);//得到天int currentYear=current.get(Calendar.YEAR);//得到年int currentMonth=current.get(Calendar.MONTH)+1;//得到月,因为从0开始的,所以要加1int currentDay=current.get(Calendar.DAY_OF_MONTH);//得到天if (preYear == currentYear && preMonth==currentMonth && preDay == currentDay) {//当年月日相同时,流水号加1String temp = String.valueOf(++index);int length = temp.length();for(int i = 0; i<3-length;i++) {sb.append("0");}sb.append(temp);} else {//不同时,从001开始pre = current;index = 1;sb.append("001");}}return sb.toString();}
流水号以年月日加上后3位数字,从001开始。
0 0
- 时间对比、流水号计算、100%统计
- 时间流水
- 统计程序的计算时间。
- PHP计算时间,统计图表
- Java订单号(时间加流水号)
- Java订单号(时间加流水号)
- 生成时间加流水号的编码
- 统计时间周,月的计算.
- SQL语法计算 统计时间日期
- java计算当前时间和对比的过期时间…
- 时间如流水啊
- 时间如流水,一去不复返
- 时间如流水
- C#--生成流水号---当前时间加随机数
- 计算机对加减乘除的计算时间的对比
- 流水号
- 流水号
- 流水号
- js中return的用法
- 【机器学习】主题模型(二):pLSA和LDA
- 孙其功陪你学——之Kinect开发之结合Unity3D进行游戏应用开发关节对应
- 使用Socket,多客户端连接服务器端程序范例
- 关于采集器启动后采集程序会在后台运行的解释
- 时间对比、流水号计算、100%统计
- 未识别的标示符string
- android telephony 之 SIM 卡文件系统
- 从object对象读取字符串
- git tag
- Hello world
- 1、OpenGL之旅+第一个OpenGL窗口
- ant 的 copy 使用<转>
- oracle thin和oci 区别