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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:20:48+00:00 2026-05-20T09:20:48+00:00

Is there a date class in Java which I can construct with a year,

  • 0

Is there a date class in Java which I can construct with a year, month, day, hour, minute, second and millisecond and then do comparisons which give the number of milliseonds between two date values, ignoring things like daylight saving, leap seconds etc? Can I use the Calendar class for this? I was thinking about doing that, but it talks about leap seconds and daylight saving, and I don’t want that to affect the calculations.

It is important that the following invariant holds true all the times:

For all y1, y2, m1, m2, d1, d2, h, m, s, ms:

(
    f(y1, m1, d1, h, m, s, ms).getTimeInMillis() - 
    f(y2, m2, d2, h, m, s, ms).getTimeInMillis()
) 
% 
(24 * 60 * 60 * 1000) == 0

I basically need to know what the function f should be.

  • 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-20T09:20:49+00:00Added an answer on May 20, 2026 at 9:20 am

    I would try using Joda DateTime where you could do

    DateTime d1 = new DateTime(y1,m1,d1,h1,m1,s1,ms1);
    DateTime d2 = new DateTime(y2,m2,d2,h2,m2,s2,ms2);
    long delta = d1.toMillis() - d2.toMillis();
    

    Also consider:

     DateTime d1 = new DateTime(y1,m1,d1,h1,m1,s1,ms1);
     DateTime d2 = new DateTime(y2,m2,d2,h2,m2,s2,ms2);
     Duration delta = new Duration( d1, d2);
     int days = delta.toPeriod().getDays();
    

    If you have unusual needs you may want to look at Joda Chronology objects.

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

Sidebar

Related Questions

Is there a Java equivalent of DateTime.MinValue and DateTime.Today in the Java Date class?
I have exchange rate table in which there are multiple date wise records with
Java date & time datatypes are as everybody knows, there's no need to focus
Can anyone advise? I have a job which runs on the hour, every hour,
Which Java class should you use for time performance measurements? (One could use any
Are there some 'date parser' library that does for dates what FParsec does to
Is there a GWT Date Time Component? Note: I am already making use of
I know there is the Date#step method, however it wants days for steps. I
I have a MySQL table where there is a 'date_added' (date) field, 'time_added' (time)
I have this table: ID(INT) DATE(DATETIME) Under the DATE column there are a lot

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.