w3resource logo


Java Programming Exercies

Java DateTime, Calendar Exercises: Get current timestamp

Secondary Nav

Java DateTime, Calendar : Exercise-20 with Solution

Write a Java program to get current timestamp.

Java Code:

import java.time.*;
public class Exercise20 {
   public static void main(String[] args)
    {
    Instant timestamp = Instant.now(); 
    System.out.println("\nCurrent Timestamp: " + timestamp+"\n"); 
    }
}

Output:

Current Timestamp: 2016-09-16T08:32:23.384Z

Java Practice online:

import java.time.*;
public class Exercise20{
   public static void main(String[] args)
    {
    Instant timestamp = Instant.now(); 
    System.out.println("\nCurrent Timestamp: " + timestamp+"\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