JDK-4679060 : Documentation of java.sql.Timestamp.getTime() is contradictory
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.sql
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2002-05-03
  • Updated: 2002-06-06
  • Resolved: 2002-06-06

Name: jl125535			Date: 05/02/2002


The javadoc for java.sql.Timestamp can be confusing.  The class desciption states that "only integral seconds are stored in the
java.util.Date component."  However, the description of getTime() claims that the method "returns the number of milliseconds ... represented by this Timestamp object."  Many people do not believe that milliseconds are "integral" seconds.

As a result, some users believe that the code given below should return

The values are NOT equal
sv: 767676767676
sv2: 767676767000

instead of

The values are equal
sv: 767676767676
sv2: 767676767676

---------- BEGIN SOURCE ----------
import java.sql.Timestamp;

public class LongValueTest
	public static void main(String[] args)
		long sv = 767676767676L;
		Timestamp time = new Timestamp(sv);
		long sv2 = time.getTime();
		if (sv == sv2)
			System.out.println("The values are equal");
			System.out.println("The values are NOT equal");
		System.out.println("sv: "+sv);
		System.out.println("sv2: "+sv2);
---------- END SOURCE ----------
(Review ID: 145942) 

JDK 1.3.x did not return the milliseconds portion of the time.  In other words, the test case would result in

The values are NOT equal
sv: 767676767676
sv2: 767676767000

with JDK 1.3.1.

(Review ID: 146854) 

EVALUATION We have gone to great lengths to reduce user confusion in this area in JDK 1.4.1. I believe additional documantation and notes supplied within the API should assist greatly here. ###@###.### 2002-06-05