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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:20:15+00:00 2026-06-02T23:20:15+00:00

I am a novice to Java programming using Netbeans. I have added jCalendar to

  • 0

I am a novice to Java programming using Netbeans. I have added jCalendar to my GUI to pick a date.

I have entered this line in Events -> “property change” code of jCalendar button,

Date date=jcalendar1.getDate(); 

So that I get the date immediately when it is changed. Am I right?

The purpose:
I want to find the difference in milliseconds from the afternoon (12:00 pm) of this date above to NOW (current date and time).
There are several programs showing the date difference but all have dates hardcoded and being a newbie i do not know how to replace it with the date that is picked. (also i am confused between the objects Date and Calendar, not able to understand the difference between them). For example, a piece from here:

http://www.java2s.com/Code/Java/Data-type/ReturnsaDatesetjusttoNoontotheclosestpossiblemillisecondoftheday.htm

if (day == null) day = new Date();
  cal.setTime(day);
  cal.set(Calendar.HOUR_OF_DAY, 12);
  cal.set(Calendar.MINUTE,      cal.getMinimum(Calendar.MINUTE));
  cal.set(Calendar.SECOND,      cal.getMinimum(Calendar.SECOND));
  cal.set(Calendar.MILLISECOND, cal.getMinimum(Calendar.MILLISECOND));
  return cal.getTime();

Here day is a Date object. How is cal (a calendar object) linked to it to enter the time. How should the cal object be defined first? How can I use this or anything else in your opinion for my program. A piece of code with detail comments will be more helpful
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-02T23:20:16+00:00Added an answer on June 2, 2026 at 11:20 pm

    Instead of using :

    Date day = new Date();
    

    Use:

    Calendar cal = Calendar.getInstance();
    cal.set (...);
    Date date = new Date(cal.getTimeInMillis());
    

    Worth abstracting this stuff out to a DateUtils class or similar, with something like the following:

    public static Date create(int year, int month, int day, int hour, int minute, int second) {
        return new Date(getTimeInMillis(year, month, day, hour, minute, second));
    }
    
    public static long getTimeInMillis(int year, int month, int day, int hour, int minute, int second, int milliseconds) {
        Calendar cal = Calendar.getInstance();
    
        cal.clear();
        cal.set(year, month, day, hour, minute, second);
        cal.set(Calendar.MILLISECOND, milliseconds);
    
        return cal.getTimeInMillis();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I am a novice in JAVA. I have been getting this file not
I have literally been searching for this for weeks. I am a novice java
Python novice here. I am using python2.7.2 on Windows7. I have installed the PyWin32
Consider me a novice to Windows environment and COM programming. I have to automate
Ok,so I'm a complete novice at programming and I just started coding in Java.
Okay, first, I'm a noob at android programming. I have taken some Java, but
I am a novice with Java. I have to implement an array of objects
I am a novice programmer who mainly uses Java. Recently I have become interested
This is not homework. I am a beginner (novice) java programmer, trying to read
i want to learn coding web apps with java using glassfish. i have bought

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.