Java Program to Get Current System Date and Time

Java program to get current system date and time

//program to get system date and time
import java.util.Date;

public class GetDateTime {
  public static void main(String args[]) {
    // instance of Date class
    Date date = new Date();

    // get date, month and year
    System.out.println(date.getDate() + "/" + (date.getMonth() + 1) + "/" + (date.getYear() - 100));

    // get complete date and time
    System.out.println(date.toString());

    // get time only
    System.out.println(date.getHours() + ":" + date.getMinutes() + ":" + date.getSeconds());
  }
}

Output

    28/4/16
    Thu Apr 28 22:40:44 IST 2016
    22:40:44
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment