在Eclipse中的基准测试中有两个字符串值。只要其中一个是空的。用户可用于登录和注销。
我希望分配一个空值,因为不是每个用户都有一个离开日期。
我将使用我的工程工作在帆点软件。
月食
public static void main(String[] args) {
// TODO Auto-generated method stub
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
String tarihEnd= null;
String tarihStart = "18/01/2023";
try {
if (tarihEnd !=null || tarihStart!=null)
{
LocalDate jobLeavingDay = LocalDate.parse(tarihEnd,sdf);
LocalDate jobStartingDay = LocalDate.parse(tarihStart,sdf);
LocalDateTime beginDate = jobLeavingDay.atTime(8, 00);
LocalDateTime endDate = jobLeavingDay.atTime(16, 30);
LocalDateTime nowDateTime = LocalDateTime.now();
if(nowDateTime.compareTo(beginDate)==1 && nowDateTime.compareTo(endDate)==-1)
System.out.println("False1");
else if(jobLeavingDay.compareTo(nowDateTime.toLocalDate())<0 && jobStartingDay.compareTo(nowDateTime.toLocalDate())<0) // jobleaving and jobstarting < nowdatetime = true
System.out.println("True1");
else if (jobStartingDay.compareTo(nowDateTime.toLocalDate())<0 && jobLeavingDay.compareTo(nowDateTime.toLocalDate()) >0)
System.out.println("False2");
else if (jobStartingDay.compareTo(nowDateTime.toLocalDate())>0)
System.out.println("True");
else if (jobStartingDay.compareTo(nowDateTime.toLocalDate())<0)
System.out.println("False3"); //jobleaving null, jobStarting_NowDate den once gelirse
}} catch (Exception e) {
tarihStart=null;
tarihEnd=null;
}
}
}帆点
身份证明在这里完成。从csv文件中提取信息。
示例:将在2022年20/12/2022开始工作的用户的实际值应该为真。
但是,即使我把>符号或给isAfter,它得到的每一次假值。
在这里编辑有什么意义?
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import sailpoint.object.*;
DateTimeFormatter sdf= DateTimeFormatter.ofPattern("dd/MM/yyyy");
Attributes attrs = link.getAttributes();
String tarih = attrs.getString("JobLeaveDate");
String tarih2 = attrs.getString("JobStartDate");
try{
if(tarih!=null || tarih2!=null {
LocalDate jobLeavingDay = LocalDate.parse(tarih, sdf);
LocalDate jobStartingDay = LocalDate.parse(tarih2, sdf);
LocalDate nowDate = LocalDate.now();
//LocalDateTime beginDate = jobLeavingDay.atTime(8, 00);
// LocalDateTime endDate = jobLeavingDay.atTime(16, 30);
// LocalDateTime nowDateTime = LocalDateTime.now();
if (jobStartingDay.compareTo(nowDate)>0)
stat="True";
else if (jobStartingDay.compareTo(nowDate)<0)
stat="False";
} } catch (Exception e) {
tarih=null;
}
return (stat) 发布于 2022-08-25 11:11:51
用你的第一个密码。这是例外,因为tarihEnd = null,但您也使用它的行:
LocalDate jobLeavingDay = LocalDate.parse(tarihEnd,sdf);
使用yout代码第二,请您提供价值税,tarih2。
低声我的代码:
public static void main(String[] args) {
DateTimeFormatter sdf = DateTimeFormatter.ofPattern("dd/MM/yyyy");
String tarihEnd = "26/08/2022";
String tarihStart = "18/01/2023";
String stat = "";
try {
if (tarihEnd != null || tarihStart != null) {
LocalDate jobLeavingDay = LocalDate.parse(tarihEnd, sdf);
LocalDate jobStartingDay = LocalDate.parse(tarihStart, sdf);
LocalDate nowDate = LocalDate.now();
if (jobStartingDay.isAfter(nowDate)) {
stat = "True";
} else if (jobStartingDay.compareTo(nowDate) < 0)
stat = "False";
}
} catch (Exception e) {
tarihStart = null;
tarihEnd = null;
}
System.out.println(stat);
}图书馆的贝娄代码:
public boolean isAfter(ChronoLocalDate other) {
if (other instanceof LocalDate) {
return this.compareTo0((LocalDate)other) > 0;
} else {
return super.isAfter(other);
}
}以及:
int compareTo0(LocalDate otherDate) {
int cmp = this.year - otherDate.year;
if (cmp == 0) {
cmp = this.month - otherDate.month;
if (cmp == 0) {
cmp = this.day - otherDate.day;
}
}
return cmp;
}如您所见,我们使用LocalDate,因此isAfter方法将返回:this.compareTo0((LocalDate)other) > 0; here other = now()
我的代码,jobStartingDay = 18/01/2023,然后是cmp = 2023-2022=1,因此是isAfter = true。18/01/2023年是今天之后的日子,isAfter = true是正确的。更容易,你应该转换为长和工作。
https://stackoverflow.com/questions/73484316
复制相似问题