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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T23:21:14+00:00 2026-05-23T23:21:14+00:00

Foo a; … Date b = a.getDate(); Date c = new Date(b.getTime()); if (b.equals(c))

  • 0
Foo a;
...
Date b = a.getDate();
Date c = new Date(b.getTime());

if (b.equals(c)) System.out.println("equal");
else System.out.println("not equal");

System.out.println(b.toString());
System.out.println(b.getTime());
System.out.println(c.toString());
System.out.println(c.getTime());

The above prints:

not equal
2011-07-23 22:24:21.834
1311459861834
Sat Jul 23 22:24:21
1311459861834

Why is this? Is this a bug in Date? Thats hard to believe.

  • 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-23T23:21:15+00:00Added an answer on May 23, 2026 at 11:21 pm

    a.getDate() obviously returns java.sql.Timestamp

    java.sql.Timestamp has different equals method than java.uti.Date which is basically

    return obj instanceof Date && getTime() == ((Date) obj).getTime();

    Timestamp however is more sophisticated and it requires the target to be Timestamp too.

    if (ts instanceof Timestamp) {
        return this.equals((Timestamp)ts);//the impl checks nanos too
      } else {
        return false;
      }
    

    You probably use Hibernate or something similar that persists java.util.Date as Timestamp.

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

Sidebar

Related Questions

Foo* set = new Foo[100]; // ... delete [] set; You don't pass the
foo\r\nbar.replace(/(foo).+/m, bar) Hello. I can not understand why this code does not replace foo
def foo(x: Int, f: Unit => Int) = println(f()) foo(2, { Unit => 3
db.foo.find().limit(300) won't do it. It still prints out only 20 documents. db.foo.find().toArray() db.foo.find().forEach(printjson) will
var foo = bar; new Func<String>(() => { var foo = ; // This
foo[0] = ?b # boo I was looking at the above example and trying
foo.C has been updated 5 times since the tag I checked out. I want
foo = new Image() foo.x = 500 foo.x => 0
Foo = Class.new Foo.class_eval do def class_bar class_bar end end Foo.instance_eval do def instance_bar
Foo = Class.new Foo.instance_eval do def instance_bar instance_bar end end puts Foo.instance_bar #=> instance_bar

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.