【问题标题】:Get every day of week within date range using hibernate query使用休眠查询获取日期范围内一周中的每一天
【发布时间】:2014-01-10 13:55:40
【问题描述】:

如何获取 2014 年 1 月 1 日至 2014 年 2 月 5 日之间的每个星期一、星期四和星期五的日期?

如果休眠查询无法实现,有什么变通的建议吗?

提前致谢!

【问题讨论】:

    标签: hibernate


    【解决方案1】:

    我不清楚您为什么要使用查询来获取此信息,除非您的问题还有更多。

    我可能会使用 Joda 库来执行此操作(假设您使用的是 Java)。

    类似:

    LocalDate currentDate = new LocalDate(2014, 1, 1);
    LocalDate endDate = new LocalDate(2014, 2, 5);
    
    while(currentDate.isBefore(endDate)) {
    
      if (currentDate.getDayOfWeek() == 1 || currentDate.getDayOfWeek() == 4 ||     currentDate.getDayOfWeek() == 5) {
        System.out.println(currentDate.toString());
      }
      currentDate = currentDate.plusDays(1);
    }
    

    【讨论】:

    • 谢谢亚历克斯!我在想如果有10万条记录被拉出来并在内存中处理,会有什么问题吗?
    • 您只需要这样做一次,因为答案不会改变。
    猜你喜欢
    • 2014-11-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多