Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to retrieve milliseconds from java.sql.Timestamp

Tags:

I have a timestamp object and need to get the milliseconds from it, can someone help me with an example code snippet ?

like image 574
Al Phaba Avatar asked May 10 '12 15:05

Al Phaba


People also ask

How do you convert timestamps to milliseconds to seconds?

You need to simply divide the milliseconds value by 1000 and you will get the value in seconds.

How do you find the Date in milliseconds?

This is the number of seconds since the 1970 epoch. To convert seconds to milliseconds, you need to multiply the number of seconds by 1000. To convert a Date to milliseconds, you could just call timeIntervalSince1970 and multiply it by 1000 every time.


1 Answers

You can use Timestamp.getTime()

Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this Timestamp object.

Example:

long timeInMilliSeconds = t.getTime(); // do magic trick here 

Note: Timestamp is extend from Date.

like image 112
Pau Kiat Wee Avatar answered Oct 28 '22 16:10

Pau Kiat Wee