Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Milliseconds to UNIX timestamp

Tags:

java

android

Anyone have any idea how I would go about converting a timestamp in milliseconds from 1970 (from Android's System.currentTimeMillis();) to a UNIX timestamp? It need only be accurate to the day.

I figure I could divide by 1000 to get seconds, and then divide by 86400 (number of seconds in a day) to get the # of days. But I'm not sure where to go from there.

Many thanks.

like image 211
t.vb.w Avatar asked Mar 10 '10 20:03

t.vb.w


3 Answers

Divide it by 1000

like image 65
thelost Avatar answered Oct 23 '22 05:10

thelost


Dividing by 1000 is enough to get a Unix timestamp. You don't need any numbers of days or anything like that.

like image 38
Chris Jester-Young Avatar answered Oct 23 '22 07:10

Chris Jester-Young


long unixTime = System.currentTimeMillis() / 1000L;
like image 45
Chirag Avatar answered Oct 23 '22 05:10

Chirag