Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8936313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:11:26+00:00 2026-06-15T10:11:26+00:00

In my Java Application i’m print all the Dates between Two dates by using

  • 0

In my Java Application i’m print all the Dates between Two dates by using below code..

List<Date> dates = new ArrayList<Date>();

    String str_date ="2012-12-01";
    String end_date ="2012-12-06";

    DateFormat formatter = new SimpleDateFormat("yyyy-mm-dd");
    Date  startDate = (Date)formatter.parse(str_date); 
    Date  endDate = (Date)formatter.parse(end_date);
    long interval = 24*1000 * 60 * 60; // 1 hour in millis
    long endTime =endDate.getTime() ; // create your endtime here, possibly using Calendar or Date
    long curTime = startDate.getTime();
    while (curTime <= endTime) {
        dates.add(new Date(curTime));
        curTime += interval;
    }
    int i=0;
    for(i=0+i;i<dates.size();i++){
        Date d =(Date)dates.get(i);
        String ds = formatter.format(d);    
        System.out.println("             " + ds+"          ");
    }

But i Want 2 types of Date like….

  1. Getting alternative Day EX:2012-12-01 2012-12-03 2012-12-06
  2. And i want Print only Saturday and Sunday in given two Dates.

Actually i’m trying to Print i+1 or i-1 it gives Array Index out of Bound..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T10:11:28+00:00Added an answer on June 15, 2026 at 10:11 am

    I think you can try in this way –

    Date startDate = (Date) formatter.parse(str_date);
    Date endDate = (Date) formatter.parse(end_date);
    
    Calendar cal = Calendar.getInstance();
    Calendar cal1 = Calendar.getInstance();
    cal.setTime(startDate);
    cal1.setTime(endDate);
    int i=0; // use this for alternative date print
    while (!cal.equals(cal1)) {
        cal.add(Calendar.DATE, 1);
        if(cal.get(Calendar.DAY_OF_WEEK)==Calendar.SATURDAY || cal.get(Calendar.DAY_OF_WEEK)==Calendar.SUNDAY)
             System.out.println(cal.get(Calendar.DAY_OF_WEEK)); 
        System.out.println(cal.getTime());
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a standalone java application that fires up several JMS consumers using the
I have created a java application on netbeans 7 .Now By using netbeans ihave
My Java application is developed using HttpClient 3. Is there any advantages of switching
My Java application is currently using ZIP as a project file format. The project
my java application has a loading task which requires two server calls which can
My java application uses log4j for logging. Using ant the project builds successfully, but
My Java application needs to send an email out to all users once per
My Java application uses two Threads. Historically grown, there are synchronized methods and dedicated
A java application is using the %PUBLIC% environment variable to get the path to
My Java application deals with large binary data files using memory mapped file (MappedByteBuffer,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.