Q:

Java program to get current system date and time

0

Java program to get current system date and time

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Get Date and Time program in Java

//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

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Core Java Example programs for Beginners and Professionals

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Java program to get input from user... >>
<< Java program to get student details...