Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java : convert long to Timestamp

I know, how to convert a Timestamp to a long, with the getTime() method.

Is there a method that convert a long to a TimeStamp?

like image 926
Adam Sh Avatar asked May 14 '12 20:05

Adam Sh


People also ask

Can we convert string to timestamp in Java?

Use TimeStamp. valueOf() to Convert a String to Timestamp in Java. We will use the TimeStamp class's own static function - valueOf() . It takes a string as an argument and then converts it to a timestamp.

Can we convert from long to int in Java?

We can convert long to int in java using typecasting. To convert higher data type into lower, we need to perform typecasting. Typecasting in java is performed through typecast operator (datatype).

How to convert date to timestamp in Java?

Java Program to Convert Date to TimeStamp 1 The constructor of the time-stamp class requires a long value. 2 So data needs to be converted into a long value by using the getTime () method of the date class (which is present in... More ...

How to assign a timestamp class to a date object?

So, you can directly assign an instance of the Timestamp class to Date. In such a case, the output of the Date object will be like Timestamp ie it would be in the format like date followed by time (to the scale of milliseconds).

How to get time in long format in Java?

String timeInLong = time.replaceAll (":", ""); System.out.println ("Time in long format : "+Long.parseLong (timeInLong)); Show activity on this post. Thanks for contributing an answer to Stack Overflow!

Do I need Java SQL timestamps?

No need for java.sql.Timestamp. The modern approach uses the java.time classes that supplant the troublesome old legacy classes such as java.sql.Timestamp & Date & Calendar.


1 Answers

The constructor is doing that:

Timestamp(long time)  
like image 91
evanwong Avatar answered Oct 05 '22 20:10

evanwong