Online Java Compiler By
JavaTpoint.com
import java.sql.Timestamp; import java.time.Instant; public class JavaTimespanExample2 { public static void main(String[] args) { Timestamp ts1 = Timestamp.valueOf("2018-09-01 09:01:15"); System.out.println("Timestamp : "+ts1); // getTime() method returns the number of milliseconds Long val=ts1.getTime(); System.out.println("1. Milliseconds : "+val); //hashCode() method returns the hash code for this object. Integer val1=ts1.hashCode(); System.out.println("2. Hash code : "+val1); // setNanos() method sets nanos value for the specified integer value. ts1.setNanos(54647); System.out.println("3. Timestamp after setting nanos : " + ts1); // toInstant() method returns an Instant which represents the same point on the time-line as this Timestamp Instant instant = ts1.toInstant(); System.out.println("4. Instant Timespan : " + instant); } }
Output