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

  • SEARCH
  • Home
  • 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 4022208
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:26:49+00:00 2026-05-20T10:26:49+00:00

public void display(Date date) { for (int i = 0; i < this.position; i++)

  • 0
public void display(Date date) {
        for (int i = 0; i < this.position; i++) {
            schedule[i].init();
            while (schedule[i].hasMoreOccurrences()) {
                Date tmp = schedule[i].nextOccurrence();
                if (tmp.compareTo(date) == 0) {
                    System.out.println(schedule[i].toString());
                    schedule[i].init();
                    break;
                }

            }
        }
    }

Basically put, the above goes through an array of “events”. Each event has a method to check is it has more occurrences and a method to get the next occurrence (which is of type date).

The method accepts a date and goes through the array and checks every event. For each event it checks if it has more occurrences. If it does, it checks if this occurrence is “equal” to the date specified. If it is, it prints the event and breaks out of the loop and moves to the next event in the array. If the next occurrence is not equal to the date given, it keeps checking as long as the event has more occurrences to check.

I know this method is SUPPOSED to print out events, however I’m getting no errors and no output. I’ve been playing around with it for a while to no avail.

I’m 100% sure my hasMoreOccurrences() and nextOccurrence() methods are working correctly because other parts of the code which relies on them heavily works.

I’m stumped :/
Thanks for the help 🙂

EDIT
I’ve printed both tmp and date and I see that they both occur on the same DATE but not the same TIME. I don’t care about the time, only about the date. Any ideas?

  • 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-05-20T10:26:49+00:00Added an answer on May 20, 2026 at 10:26 am

    There are several ways to compare two Date instances without taking the time into account.

    1. Convert both to Calendar and reset the fields of desinterest.

      Calendar calendar = Calendar.getInstance();
      calendar.setTime(date);
      calendar.set(Calendar.HOUR_OF_DAY, 0);
      calendar.set(Calendar.MINUTE, 0);
      calendar.set(Calendar.SECOND, 0);
      calendar.set(Calendar.MILLISECOND, 0);
      

      And then compare them.

      if (calendar1.equals(calendar2))
      

      (true, it’s horrible, that’s why JodaTime exist and JSR-310 is underway)

    2. Format to String without time and then parse back.

      SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
      date = sdf.parse(sdf.format(date));
      

      And then compare them.

      if (date1.equals(date2))
      
    3. Use JodaTime from the beginning on.

      if (dateTime1.toLocalDate().equals(dateTime2.toLocalDate()))
      

    Note that I used x.equals(y) instead of x.compareTo(y) == 0 because that’s how you’re supposed to compare objects on equality in Java.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

public void display(Date date) { boolean loop = true; System.out.println(Events on + date.toString()); for
public void test() { List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); for (int
public abstract class Master { public void printForAllMethodsInSubClass() { System.out.println (Printing before subclass method
public class Animal { public void eat() { System.out.println("I eat like a generic Animal.");
public void displayData(String [] names, int []scores, char [] grades){ for (String name :
Here is my code to fetch and display date: import java.util.Calendar; public class Employee
I'm using AsyncTask to display a progressBar while loading Rss News. Because this is
public void MyTest() { bool eventFinished = false; myEventRaiser.OnEvent += delegate { doStuff(); eventFinished
public void CardToPile() { waste.push(reserve.pop); }
public void Save() { XmlSerializer Serializer = new XmlSerializer(typeof(DatabaseInformation)); /* A first chance exception

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.