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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:44:45+00:00 2026-06-18T02:44:45+00:00

I want to convert two dates to milliseconds, but the given result is wrong,

  • 0

I want to convert two dates to milliseconds, but the given result is wrong, is there anything wrong with code?, how to solve it otherwise…

GregorianCalendar c1 = new GregorianCalendar();
GregorianCalendar c2 = new GregorianCalendar();

c1.set(2013, 01, 31, 16, 44, 49);
c2.set(2013, 02, 01, 12, 59, 55);

System.out.println("c1 = "+c1.getTimeInMillis()+"\nc2 = "+ c2.getTimeInMillis());

output:
c1 = 1362300289619
c2 = 1362113995619

After caculating the time, it gives this result: 0Month -2Day -3Hour -44Min -54Sec
which is wrong. And must be something like this: 0Month 0Day 20Hour 15Min 6Sec.

c1 is bigger then c2, because it gives wrong result, but why it happened that c1 become bigger then c2, in such case it is not possible to calculate the time between two dates.
if someone knows please help me, thanks in advance.

  • 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-18T02:44:46+00:00Added an answer on June 18, 2026 at 2:44 am

    Months are 0-based, so in your example, c1 is the 31st of February, which is interpreted as the 3rd of March (only 28 days in February) and c2 is on the 1st of March.

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

Sidebar

Related Questions

I want to convert a column of numbers to numeric, but there are certain
I want to search clients that got to shop between two dates. The code
I want to compare two dates in C# i have tried Toshortdate() but its
I want to compare two dates. In pseudo-code: If the dueDate > now or
I have a array of two dimensions object[,] data; . I want to convert
Hey! I want to convert 123456 to 00:20:34.56 where the two digits to the
I want to convert a number to hex and store the result in a
Is there a way to compare two dates (which include time) ignoring the time?
I want to compare two dates; one taken from a Date column in SQL
I have two inputs Time and Date. I want to convert these fields to

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.