字符串到日期+治疗+日期到字符串

时间:2013-05-13 16:52:01

标签: xsd business-rules ilog jrules

我正在使用WODM规则设计器V7.5,我的 XOM XSD

我应该将交易日期与当前日期进行比较,因此如果客户进行交易,其账户的到期日期应该增加一年!

XOM 中的日期为字符串,因此在 BOM BOM到XOM映射部分中我创建了2种方法:

  • 将实际日期作为字符串返回的字词,在日历上用语言表示为:

    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    Date date = new Date();
    String s = dateFormat.format(date);
    return s;
    
  • 获取字符串,将其转换为日期格式,将年份加1并返回字符串,语言为: {this} NewDate({0})

    String[] splitdata = d1.split("-");
    int month = Integer.parseInt(splitdata[0]);
    int day = Integer.parseInt(splitdata[1]);
    int year = Integer.parseInt(splitdata[2]);
    Calendar cal = Calendar.getInstance();
    cal.set(year, month, day);
    Date date = cal.getTime();
    date.setYear(date.getYear() + 1);
    DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String s = dateFormat.format(date);
    return s;
    

规则如下:

definitions 
set 'variable1' to calendar NewDate (the transaction date of transaction) ; 
if 
    the transaction date of transaction is today on the calendar 
    then 
        set the expiration date of account to variable1 ; 

我输入交易日期如下:“2013-05-13”,我期待:“2014-05-13”在到期日期变量中,但是我明白了 0181-10-05

任何人都可以提供帮助?感谢。

1 个答案:

答案 0 :(得分:2)

您分割字符串的方式是错误的,因为年份作为第一个字段输入,您试图从该字段获取日期,即字段的顺序。

基本上,您的代码应包含(注意索引):

int month=Integer.parseInt(splitdata[1]); 
int day=Integer.parseInt(splitdata[2]); 
int year=Integer.parseInt(splitdata[0]);