How to get current Unix Timestamp in Java

The below code shows you the way to get current unix timestamp in Java.

TimestampExample.java
package com.bytenota;

public class TimestampExample {
    
    public static void main(String[] args) {
        long currentTimestamp = System.currentTimeMillis() / 1000L;
        System.out.println(currentTimestamp);
    }
}

Output

1512014327

Leave a Reply

avatar