Java Program to Get Current Date/Time

Java Programming Java8Object Oriented Programming

This is a very easy method to get current date and time in Java. You can use a simple Date object with toString() method to print the current date and time as follows −

Example

Live Demo

import java.util.Date;
public class DateDemo {
   public static void main(String args[]) {
      // Instantiate a Date object
      Date date = new Date();
      // display time and date using toString()
      System.out.println(date.toString());
   }
}

Output

Sun Apr 22 19:07:56 UTC 2018


raja
Published on 26-Apr-2018 14:48:16
Advertisements