Java Date 类型时间运算,对年做减法运算计算工龄得分

/*** 工龄折算分数* 1.1.1小学:记60分结合折算0.54分* 1.1.2初中:记70分结合折算0.63分* 1.1.3中专(高中):记80分结合折算0.72分* 1.1.4大专:记90分结合折算0.81分* 1.1.5本科(及以上):记100分结合折算0.9分* @param workYears* @return*/public static double getWorkYearsScore(Date workYears) {SimpleDateFormat formatter = new SimpleDateFormat("YYYY-MM-DD");ParsePosition pos = new ParsePosition(0);Date startWorkYear = formatter.parse(formatter.format(workYears), pos);ParsePosition pos2 = new ParsePosition(0);Date nowDate = formatter.parse(formatter.format(new Date()), pos2);//将Date类型转化为LocalDateZoneId zoneId = ZoneId.systemDefault();Instant instant = startWorkYear.toInstant();LocalDate localstartWorkYear = instant.atZone(zoneId).toLocalDate();Instant instant2 = nowDate.toInstant();LocalDate localnowDate = instant2.atZone(zoneId).toLocalDate();Period period = Period.between(localstartWorkYear, localnowDate);int years = period.getYears();double score;if (years >= 0 && years <= 3) {score = 0.3;} else if (years >= 4 && years <= 6) {score = 0.35;} else if (years >= 7 && years <= 10) {score = 0.4;} else if (years >= 11 && years <= 20) {score = 0.45;} else {score = 0.5;}return score;}


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部