w3resource logo


Java Programming Exercies

Java DateTime, Calendar Exercises: Get seconds since 1970

Secondary Nav

Java DateTime, Calendar : Exercise-37 with Solution

Write a Java program to get seconds since 1970.

Java Code:

public class Exercise37 {
  public static void main(String[] args)
   {
     long seconds = System.currentTimeMillis() / 1000l;
     System.out.println("\nSeconds since 1970: "+seconds+"\n");
   }
}

Sample Output :

Seconds since 1970: 1474277300 

Java Practice online:

public class Exercise37 {
  public static void main(String[] args)
   {
     long seconds = System.currentTimeMillis() / 1000l;
     System.out.println("\nSeconds since 1970: "+seconds+"\n");
   }
}



Join our Question Answer community to learn and share your programming knowledge.

Help the community:

Python: Fizzbuzz

C++: Decimal to binary conversion

JavaScript: Need Help in JavaScript

Python: Help me with this program