How to get the current date and time in seconds using Java

1 Answer

0 votes
import java.util.Date; 

public class MyClass {
    public static void main(String args[]) {
        long seconds = (new Date().getTime()) / 1000; 

        System.out.println(seconds);
    }
}



/*
run:

1646386214

*/

 



answered Mar 4, 2022 by avibootz
...