使用java对若报表强制参评人员名单在10月1日至12月31日刷新则用下一年3月31日来计算员工暂定级是否满一年若在1月1号至3月31日之间刷新则用当年3月31日来计算员工暂定级是否满一年若报表是在4月1日至9月30日之间刷新则用当年9月30日来计算员工暂定级是否满一年;
可以使用Java的日期类(如java.util.Date或java.time.LocalDate)来计算员工暂定级是否满一年。根据给定的报表刷新日期,可以确定计算员工暂定级是否满一年的参考日期。
以下是一个示例代码,演示如何计算员工暂定级是否满一年:
import java.time.LocalDate;
public class Employee {
private LocalDate hireDate;
// 假设员工的入职日期在构造函数中设置
public Employee(LocalDate hireDate) {
this.hireDate = hireDate;
}
public boolean isOneYearOrMore() {
LocalDate referenceDate = getReferenceDate();
// 计算入职日期与参考日期之间的年份差异
int yearsDifference = referenceDate.getYear() - hireDate.getYear();
if (yearsDifference > 0) {
// 如果年份差异大于0,则入职日期已经满一年
return true;
} else if (yearsDifference == 0) {
// 如果年份差异等于0,则比较月份和日期
int hireMonth = hireDate.getMonthValue();
int hireDay = hireDate.getDayOfMonth();
int referenceMonth = referenceDate.getMonthValue();
int referenceDay = referenceDate.getDayOfMonth();
if (referenceMonth > hireMonth) {
// 如果参考月份大于入职月份,则入职日期已经满一年
return true;
} else if (referenceMonth == hireMonth) {
// 如果参考月份等于入职月份,则比较日期
if (referenceDay >= hireDay) {
// 如果参考日期大于等于入职日期,则入职日期已经满一年
return true;
}
}
}
// 入职日期未满一年
return false;
}
private LocalDate getReferenceDate() {
LocalDate currentDate = LocalDate.now();
// 获取当前月份
int currentMonth = currentDate.getMonthValue();
// 根据报表刷新日期确定参考日期
if (currentMonth >= 1 && currentMonth <= 3) {
// 1月1日至3月31日之间刷新,用当年3月31日来计算
return LocalDate.of(currentDate.getYear(), 3, 31);
} else if (currentMonth >= 4 && currentMonth <= 9) {
// 4月1日至9月30日之间刷新,用当年9月30日来计算
return LocalDate.of(currentDate.getYear(), 9, 30);
} else {
// 其他时间段刷新,用下一年3月31日来计算
return LocalDate.of(currentDate.getYear() + 1, 3, 31);
}
}
public static void main(String[] args) {
// 假设员工的入职日期为2021年1月1日
Employee employee = new Employee(LocalDate.of(2021, 1, 1));
// 判断员工的暂定级是否满一年
boolean isOneYearOrMore = employee.isOneYearOrMore();
System.out.println("员工的暂定级是否满一年:" + isOneYearOrMore);
}
}
上述示例中,Employee类表示一个员工,具有入职日期hireDate属性和判断员工暂定级是否满一年的方法isOneYearOrMore()。getReferenceDate()方法根据报表刷新日期确定参考日期,然后在isOneYearOrMore()方法中使用参考日期和入职日期进行比较,判断是否满一年。最后,在main()方法中创建一个Employee对象,设置入职日期为2021年1月1日,并调用isOneYearOrMore()方法判断员工的暂定级是否满一年
原文地址: http://www.cveoy.top/t/topic/iRRE 著作权归作者所有。请勿转载和采集!