tags:

views:

59

answers:

2

How can I get seconds from 1970 in java ?

+10  A: 

You mean epoch time? You can use

long epoch = (System.currentTimeMillis()/1000L);

that will get the number of seconds since January 1st 1970 UTC time.

this belongs on StackOverflow though, it will be moved there shortly so please don't repost.

John T
Voting you up for a more complete answer:)
phoebus
You should divide by 1000L rather than 1000 to avoid unecessary casting.
Adamski
@Adamski haven't used java in a while, I only program now for making personal tasks faster :) Thanks for the heads up.
John T
+3  A: 

java.lang.System.currentTimeMillis() gives you the time since Jan 1, 1970 in milliseconds. Just divide by 1000 to get the time in seconds.

phoebus
+1 assuming it was posted simultaneously, as it happens all the time
stacker