gpt4 book ai didi

java - 如何在 Oracle ADF 中向用户获取的日期添加天数

转载 作者:太空宇宙 更新时间:2023-11-04 10:38:51 25 4
gpt4 key购买 nike

我想迭代每一行中的一个月。
这是我的代码,运行时它不会迭代月份。

/** function receive date and integer then add the integer to the date then return the result date.
(e.g. if you send 2013/07/13 and 5 to this function the function will return 2013/07/18 */

public static Date addDayToOracleDate(oracle.jbo.domain.Date date, int days)
{
if (date != null)
{
Calendar c1 = Calendar.getInstance();
c1.setTime(date.getValue());
c1.add(Calendar.DATE, days);
java.util.Date javaUtilDate = c1.getTime();
long javaMilliseconds = javaUtilDate.getTime();
java.sql.Date javaSqlDate = new java.sql.Date(javaMilliseconds);
return new oracle.jbo.domain.Date(javaSqlDate);
}
return null;
}
public void genrateActionLSNR(ActionEvent actionEvent) {

BindingContainer bc = BindingContext.getCurrent().getCurrentBindingsEntry();
DCIteratorBinding CEmpLoans1Iterator = (DCIteratorBinding)bc.get("CEmpLoans1Iterator");
DCIteratorBinding CEmpLoans1DIterator = (DCIteratorBinding)bc.get("CEmpLoansD2Iterator");


Number loanValue = (Number)CEmpLoans1Iterator.getCurrentRow().getAttribute("LoanValue");
Number noOfMonths = (Number)CEmpLoans1Iterator.getCurrentRow().getAttribute("NoOfMonths");
Date firstInstallmentDate = (Date)CEmpLoans1Iterator.getCurrentRow().getAttribute("FirstInstallmentDate");

Number result = (Number)loanValue.div(noOfMonths);
Date hh = firstInstallmentDate;
for(int i=0; i<noOfMonths.getValue();i++){
addDayToOracleDate(hh, 30);
bc.getOperationBinding("CreateInsert1").execute();

CEmpLoans1DIterator.getCurrentRow().setAttribute("InstallmentVal", result);
CEmpLoans1DIterator.getCurrentRow().setAttribute("LoansMonths", hh);
System.out.println(hh);

//bc.getOperationBinding("Commit").execute();
}

最佳答案

您假设每个月有 30 天,这显然是错误的。如果您想在日期上添加一个月,请尝试 c1.add(Calendar.MONTH, 1);

关于java - 如何在 Oracle ADF 中向用户获取的日期添加天数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49235184/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com