Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 仅动态列出特定日期的两个日期之间的日期_Java_Date_Datetime_Time - Fatal编程技术网

Java 仅动态列出特定日期的两个日期之间的日期

Java 仅动态列出特定日期的两个日期之间的日期,java,date,datetime,time,Java,Date,Datetime,Time,我有一个演示文稿表,其中包含以下值: ID DAY START END STARTDATE ENDDATE 622 Monday 12:00:00 02:00:00 01-05-2016 04-06-2016 623 Tuesday 12:00:00 02:00:00 01-05-2016 04-06-2016 624 Wednesday 08:00:00 10:0

我有一个
演示文稿
表,其中包含以下值:

ID     DAY         START       END      STARTDATE       ENDDATE
622   Monday     12:00:00    02:00:00   01-05-2016     04-06-2016 
623   Tuesday    12:00:00    02:00:00   01-05-2016     04-06-2016 
624   Wednesday  08:00:00    10:00:00   01-05-2016     04-06-2016 
625   Thursday   10:00:00    12:00:00   01-05-2016     04-06-2016 
因此,基本上,我的
STARTDATE
是2016年5月1日,直到
ENDDATE
2016年6月4日

我想知道如何列出这两个日期之间的日期,如下所示:

Calendar cal = Calendar.getInstance();
                cal.setTime(presentationDateStart);
                while (cal.getTime().before(presentationDateEnd)) {
                    cal.add(Calendar.DATE,1);
                    System.out.println("poop "+cal.getTime());

                }
但是,这将以这种格式列出所有可能的日期:
Sun May 08 00:00:00 SGT 2016

如何在我的
演示文稿
表中根据
日期
动态获取特定日期?
presentation
表的值始终是动态的

更新:

我只想在我的
演示文稿
表格中列出只包含日期的日期列表。格式对我来说并不重要

预期成果:

Mon May 02 00:00:00 SGT 2016
Tue May 03 00:00:00 SGT 2016
Wed May 04 00:00:00 SGT 2016
Thu May 05 00:00:00 SGT 2016
Mon May 09 00:00:00 SGT 2016
Tue May 10 00:00:00 SGT 2016
Wed May 11 00:00:00 SGT 2016
Thu May 12 00:00:00 SGT 2016 so on until end of the date
更新

这是我的JAVA代码:

            String presentationID = null;
            String presentationDay = null;
            Date presentationStart = null;
            Date presentationEnd = null;
            Date presentationDateStart = null;
            Date presentationDateEnd = null;
            String presentationFreeID = null;

            List list1 = new ArrayList() ;
            list1 = GenerateScheduleDAO.getPresentation();
            PresentationBean[] presentation = new PresentationBean[list1.size()];
            for(int c = 0 ; c < list1.size() ; c++){

                presentation[c] = (PresentationBean) list1.get(c);

                presentationID = presentation[c].getPresentationID();
                presentationDay = presentation[c].getPresentationDay();
                presentationStart = presentation[c].getPresentationStart();
                presentationEnd = presentation[c].getPresentationEnd();
                presentationDateStart = presentation[c].getPresentationDateStart();
                presentationDateEnd = presentation[c].getPresentationDateEnd();
                presentationFreeID = presentation[c].getFreeID();

                System.out.println(" pFID11: "+ presentationFreeID +" pID: "+ presentationID +" pDay: "+ presentationDay+ " PStart: "+ presentationStart+" pEnd: "+ presentationEnd+" DStart: "+presentationDateStart+" EDate: "+ presentationDateEnd);

                Calendar cal = Calendar.getInstance();
                cal.setTime(presentationDateStart);
                while (cal.getTime().before(presentationDateEnd)) {
                    cal.add(Calendar.DATE,1);
                    System.out.println("poop "+cal.getTime());

                }

            }    
String presentationID=null;
字符串presentationDay=null;
Date presentationStart=null;
Date presentationEnd=null;
日期presentationDateStart=null;
日期presentationDateEnd=null;
字符串presentationFreeID=null;
List list1=新的ArrayList();
list1=GenerateScheduleDAO.getPresentation();
PresentationBean[]presentation=新PresentationBean[list1.size()];
对于(int c=0;c

在db中,
DAY
存储在
VARCHAR2
中。您可以使用
日历。DAY\u OF u WEEK
获取日索引,并仅打印(包括)所需的天数

Calendar cal = Calendar.getInstance();
cal.setTime(presentationDateStart);
while (cal.getTime().before(presentationDateEnd)) {
    cal.add(Calendar.DATE,1);
    if(cal.get(Calendar.DAY_OF_WEEK) == 2 || cal.get(Calendar.DAY_OF_WEEK) == 3 || cal.get(Calendar.DAY_OF_WEEK) == 4 || cal.get(Calendar.DAY_OF_WEEK) == 5){
        //2, 3 ,4 ,5 are the index of days mon-Thu
        //constants available too : Calendar.MONDAY ... 
        System.out.println("poop "+cal.getTime());
    }
}//date is before endDate
如果您有一个日索引的动态源,您可以将此列表与它进行比较(数组或arraylist)

有关
每周工作日的更多信息

编辑: 我已经提到,您可以使用动态日索引数组 以下是我的意思示例:

ArrayList<Integer> dayIndex = getDayIndex();// could be from DB, API... it contains day index (1,4,6) the days you want to include
if(dayIndex .contains(cal.get(Calendar.DAY_OF_WEEK)){
    System.out.println("poop "+cal.getTime());
}
ArrayList dayIndex=getDayIndex();//可能来自DB,API。。。它包含要包括的天数索引(1,4,6)
if(dayIndex.contains(cal.get(日历日,每周)){
System.out.println(“poop”+cal.getTime());
}

您可以使用
Calendar.DAY\u OF u WEEK
获取日期索引,并仅打印(包括)所需的日期

Calendar cal = Calendar.getInstance();
cal.setTime(presentationDateStart);
while (cal.getTime().before(presentationDateEnd)) {
    cal.add(Calendar.DATE,1);
    if(cal.get(Calendar.DAY_OF_WEEK) == 2 || cal.get(Calendar.DAY_OF_WEEK) == 3 || cal.get(Calendar.DAY_OF_WEEK) == 4 || cal.get(Calendar.DAY_OF_WEEK) == 5){
        //2, 3 ,4 ,5 are the index of days mon-Thu
        //constants available too : Calendar.MONDAY ... 
        System.out.println("poop "+cal.getTime());
    }
}//date is before endDate
如果您有一个日索引的动态源,您可以将此列表与它进行比较(数组或arraylist)

有关
每周工作日的更多信息

编辑: 我已经提到,您可以使用动态日索引数组 以下是我的意思示例:

ArrayList<Integer> dayIndex = getDayIndex();// could be from DB, API... it contains day index (1,4,6) the days you want to include
if(dayIndex .contains(cal.get(Calendar.DAY_OF_WEEK)){
    System.out.println("poop "+cal.getTime());
}
ArrayList dayIndex=getDayIndex();//可以来自DB、API……它包含要包括的天数索引(1,4,6)
if(dayIndex.contains(cal.get(日历日,每周)){
System.out.println(“poop”+cal.getTime());
}


这还不够清楚,无法回答。请提供一些示例,说明您的意思,并提供足够的上下文来描述一组明确的规则。问题并不清楚。顺便说一句,您可以在输出格式中添加当天的检查。您的意思是使用周中的天吗?@direwolf7在函数顶部声明一个结果列表在上。以相同的方式生成日期,然后仅当格式中的日期是您想要的日期时才添加到结果列表中。在所有日期之后,从函数返回该列表。更新了my question@Jimgarrison这还不够清楚,无法回答。请提供一些示例说明您的意思,并提供足够的上下文,以便规则集是可以描述的。问题不清楚。顺便说一句,你可以在输出格式中添加一个日期检查。你的意思是使用周的天吗?@direwolf7在函数顶部声明一个结果列表。以同样的方式生成日期,然后仅当格式中的日期是你想要的日期时才添加到结果列表中。毕竟日期,从函数中返回该列表。更新了我的问题@JimGarrisonThank you@yazan。我完全理解您的代码。但我认为这是硬编码的。正如我前面提到的,
演示
表是动态的。日期可能会改变。不一定是周一、周二、周三和周四。我给出的值只是一个示例le…@user6308605我的答案已经有了。你可以提供一个日索引数组(动态)根据日期筛选日期的步骤theat@user6308605这是正确的答案,具体取决于您如何将演示表转换为Java。您需要告诉我们如何访问这些信息。很抱歉@Yazan我不了解
getDayIndex()
。我尝试了,但它出现了错误。我如何更正此问题?这是一个方法(不是Java API中的方法)我只是随便给了一个名字,不管怎样,这个方法应该返回
演示表
或者你想要打印的天数列表。