You can also try
Calendar calendar = Calendar.getInstance();
System.out.println(calendar.getTimeInMillis());
getTimeInMillis() - the current time as UTC milliseconds from the epoch
Also try System.currentTimeMillis()
Using the java.time
framework built into Java 8 and later.
import java.time.Instant;
Instant.now().toEpochMilli(); //Long = 1450879900184
Instant.now().getEpochSecond(); //Long = 1450879900
This works in UTC because Instant.now()
is really call to Clock.systemUTC().instant()
https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html
Source: Stackoverflow.com