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 8374921
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:02:37+00:00 2026-06-09T15:02:37+00:00

I’m getting a bit stuck with date comparison in Java/Android DateFormat df = new

  • 0

I’m getting a bit stuck with date comparison in Java/Android

            DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm");
                Calendar now = Calendar.getInstance();
                Calendar c;

                c = Calendar.getInstance();
                c.set(settings.getInt("year", 0), settings.getInt("month", 0), settings.getInt("day", 0), settings.getInt("hour", 0), settings.getInt("minute", 0));

                views.setTextViewText(R.id.textView4, String.valueOf(c.getTime().before(now.getTime())));
                views.setTextViewText(R.id.textView2, String.format("%s - %s", df.format(c.getTime()), df.format(now.getTime())));

                int timeout = 0;
                while( c.getTime().before(now.getTime()) )
                {
                    c.add(Calendar.SECOND, 30);
                    c.add(Calendar.MINUTE, 12);
                    c.add(Calendar.HOUR_OF_DAY, 6);
                    isHigh = 1 - isHigh;
                    timeout++;
                    if( timeout >= 400 )
                        break;
                }
                views.setTextViewText(R.id.textView5, String.valueOf(c.getTime().before(now.getTime())));
                views.setTextViewText(R.id.textView3, String.format("%s - %s", df.format(c.getTime()), df.format(now.getTime())));

The idea of this is it takes a starting date from saved settings, and adds 6:12:30 to the clock until it passes the current time.

However, my textboxes give me the following:

false : 09/07/12 04:20 – 11/08/12 00:00

false : 09/07/12 04:20 – 11/08/12 00:00

Why is 9th July 2012 returning false when calling “before(11th Aug 2012)”?

If I change the “.before” to “.after”, I get this:

true : 09/07/12 04:20 – 11/08/12 00:00

true : 20/10/12 15:40 – 11/08/12 00:00

Which doesn’t seem to make any sense.

Any ideas what I’m doing wrong? Thanks

  • 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-09T15:02:39+00:00Added an answer on June 9, 2026 at 3:02 pm

    I wonder whether it’s because your “year” setting is 12 rather than 2012. Then you’d be comparing 09/07/2012 with 11/08/0012 – but you can’t tell because of your date format.

    For diagnostic purposes, change your format string to "dd/MM/yyyy HH:mm" and try again.

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

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have thousands of HTML files to process using Groovy/Java and I need to
I'm parsing an XML file, the creators of it stuck in a bunch social
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.