Java time issues

I have a problem of inconsistency with time objects

Time time1 =  new Time(72000000); //21:00
Time time2 = new Time(new Date().getTime()); //before 21 pm

time2.before(time1); 

The last line always returns false, why?

+4
source share
4 answers

It does not do what you think it should do!

Time time1 =  new Time(72000000);

See this:

Time

public Time(long time)

Constructs a Time object using a milliseconds time value.

Parameters:
    time - milliseconds since January 1, 1970, 00:00:00 GMT; a negative number is milliseconds before January 1, 1970, 00:00:00 GMT

Now, I hope you understand ...

+1
source

Time:

A thin shell around the java.util.Date class that allows the JDBC API to identify this as an SQL TIME value. The Time class adds formatting and parsing operations to support JDBC escape syntax for time values. Date components must be set to the "zero era" of January 1, 1970 and should not be available.

http://docs.oracle.com/javase/7/docs/api/java/sql/Time.html

21:00 1970 - . , "".

+2

, , Time java.sql.Time.

java.util.Date, . JDBC (SQL) .

:

Time time1 =  new Time(72000000);

... , 1 1970 21:00. .

0

, time1 14:00. .

 Time time1 =  new Time(72000000); //21:00
 System.out.println(time1); //prints 14:00
 System.out.println(new Date());
 Time time2 = new Time(new Date().getTime()); //before 21 pm
0

All Articles