You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Drools 7.49版本date-effective属性的日期时间格式问题咨询

解决Drools 7.49中date-effective带时间格式不生效的问题

在Drools 7.49版本中,date-effective属性默认仅识别纯日期格式,若要使用带时间的格式,只需通过配置指定对应的日期时间解析规则即可,无需自定义逻辑或在where子句添加额外判断,具体操作如下:

  • 配置Drools的日期时间格式
    在创建KnowledgeBase时,通过KnowledgeBaseConfiguration设置drools.dateformat属性,指定包含时间的格式模板。比如针对"4-Sep-2018 08:00"这种格式,可设置模板为dd-MMM-yyyy HH:mm,示例代码:

    KnowledgeBaseConfiguration config = KnowledgeBaseFactory.newKnowledgeBaseConfiguration();
    config.setProperty("drools.dateformat", "dd-MMM-yyyy HH:mm");
    KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase(config);
    
  • 处理Locale兼容问题
    如果系统默认Locale不是英文,Sep这类英文月份缩写可能无法被正确解析,需同时指定Locale:

    config.setProperty("drools.locale", "en_US");
    
  • 确保规则格式与配置匹配
    规则文件中date-effective的字符串格式必须和drools.dateformat完全一致,比如注意HH(24小时制)和hh(12小时制)的区别,空格、连字符等分隔符也要严格对应。

内容的提问来源于stack exchange,提问作者user22430171

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 21:12:33