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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T22:42:05+00:00 2026-06-14T22:42:05+00:00

I have an application which use the current date and a date that is

  • 0

I have an application which use the current date and a date that is chose by user using date picker as follow:

  • If the date that the user chose is more than the current date +280 day,
    some code will be executed.

  • If the date that the user chose is less than the current date , some
    code will be executed.

I used this code to do so ..

    Calendar start2 = Calendar.getInstance();

       int birthYear = birthDayDatePicker.getYear();
            int birthMonth = birthDayDatePicker.getMonth();
            int birthDay = birthDayDatePicker.getDayOfMonth();

            start2.set(birthYear, birthMonth, birthDay);

           Calendar cal2 = Calendar.getInstance();
           cal2.setTime(birthDate);
           cal2.add(Calendar.DAY_OF_MONTH,daysToAdd);
 birthDayChosenCalender.set(birthYear,birthMonth,birthDay);
         MaxBirthDayCalender.set(currentYear, currentMonth, currentDay);

          long diff = birthDayChosenCalender.getTimeInMillis() - MaxBirthDayCalender.getTimeInMillis(); //result in millis
          long daysBetween = diff / (24 * 60 * 60 * 1000);
          System.out.println("Days between ,,,,,,,,,,,,,,,,,,"+daysBetween);

          if(MaxBirthDayCalender.before(birthDayChosenCalender) && daysBetween <= 280){

do sth }

Is there any other clean way to do that ! because this way is not working well !

  • 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-14T22:42:06+00:00Added an answer on June 14, 2026 at 10:42 pm

    The other clean way to do it is to use the Joda Time library.

    Other than that, everything can be done using millis and a single calendar instance:

    Calendar pickedDate = new GregorianCalendar(
            picker.getYear(), 
            picker.getMonth(), 
            picker.getDayOfMonth());
    long pickedTime = pickedDate.getTimeInMillis();
    long now = new Date().getTime();
    
    if (pickedTime - now <= (280 * 24 * 60 * 60 * 1000)) { // 280 days in milliseconds
      // ...
    }
    

    Should cover the requirement:

    I have an application which use the current date and a date that is chose by user using date picker as follow:

    • If the date that the user chose is more than the current date +280 day, some code will be executed.
    • If the date that the user chose is less than the current date , some code will be executed.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have C# application that makes use of some C libaries(which I have written
I have an application which needs to be able to write to Any User/Current
I am working on an application which use user location updates, I have got
I have application which needs to use a dll (also written by me) which
I have an Access application which use SQLServer 2008 R2 as database. When I
I have an application which will use WCF to serve up various chunks of
I have an application in which we use a hand-made build system.The reason for
I have a socket application which I can use in local network, at home.
I have an application which runs multiple threads. I use MadExcept to catch errors
I have a simple C# Console application in which I use FileSystemWatcher and Moving

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.