import java.util.Date; public class DateExample { public static void main(String[] args) { Date currentDate = new Date(); int seconds = currentDate.getSeconds(); System.out.println("Seconds: " + seconds); } }
import java.util.Date; public class DateExample { public static void main(String[] args) { Date specificDate = new Date(1625893200000L); int seconds = specificDate.getSeconds(); System.out.println("Seconds: " + seconds); } }This example creates a Date object with a specific date and time (June 10, 2021 at 12:00:00 AM UTC), and uses getSeconds() to retrieve the seconds value. It then prints this value to the console. The java.util.Date class is part of the Java Standard Library.