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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:55:03+00:00 2026-05-31T10:55:03+00:00

Good Day . I just wanna ask about adding days in a given date.

  • 0

Good Day .
I just wanna ask about adding days in a given date.
I have a jtexfield (txtStart) and another jtexfield(txtExpiry).
I need to display in txtExpiry the date after 102 days from the date in txtStart.
I am using KEYRELEASED event. after i input in txtStart, the date with additional 102 days shall appear in txtExpiry.

here’s my code but it’s still erroneous.

private void txtStartKeyReleased(java.awt.event.KeyEvent evt) {
// TODO add your handling code here:
    // set calendar to 1 Jan 2007
    int a = Integer.parseInt(txtStart.getText());     
    Calendar calendar = new GregorianCalendar(a,a,a);

     calendar.add(Calendar.DAY_OF_MONTH,102);
     PrintCalendar(calendar);
  }

   private void PrintCalendar(Calendar calendar){
        // define output format and print
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");         
        String date = sdf.format(calendar.getTime());
        long add = Date.parse(date);
        txtExpiry.setText(add);  -----> this part here also has an error.
     }

my code still won’t generate the date in txtExpiry. Thanks in advance

Here’s the right code after receiving help:

 private void txtStartKeyReleased(java.awt.event.KeyEvent evt) {
       try {    

        Date date1;
        date1 = new SimpleDateFormat("yyyy-MM-dd").parse(txtStart.getText());
        System.out.println(date1);

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");     
        Calendar cal  = Calendar.getInstance();
                      cal.setTime(date1);
                        cal.add(Calendar.DATE, 102);
                        String expDateString = sdf.format(cal.getTime());
                        txtExpiry.setText(expDateString);
     }catch (ParseException ex) {
      Logger.getLogger(ClientInfo.class.getName()).log(Level.SEVERE, null, ex);
     } 
}  
  • 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-31T10:55:04+00:00Added an answer on May 31, 2026 at 10:55 am

    Use

    yyyy-MM-dd
    

    Note: Capital MM

    See : SimpleDateFormat

    Now, once you have the date instance you could use Calendar to do the days arithmetic

    Calendar cal = Calendar.getInstance();
    cal.setTime(parsedDate);
    cal.add(Calendar.DATE, 102);
    String expDateString = dateFormatter.format(cal.getTime());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Good day. I have a PHP & MySql background, and I'm just starting with
Good day. I just want to consult about using websphere as san application server
Good Day, I just started to learn HTML5 - have no issues, everything's going
//Good day. This is just a part of my source code. My main predicament
Good day. I have little usage of Flash CS4, however i have to build
Good day, If I have for example the documents which have the following fields
Good day, I've just started teaching myself VB.net. I'm trying to create a simple
After working in good ole' c++ all day, I like to have a few
Good Day, I have been trying various methods both found on here and in
Good Day, I have two connection strings defined in my web.config file. <connectionStrings> <add

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.