How to get current system date and time in Java?

Get current system date and time in Java: In this program, we are getting the system’s current date and time and printing in full format.

Steps to get current system date and time in Java:

  • Include java.util.Date package in the program.
  • Create an object of Date class.
  • Print the object of Date class in string format.

Consider the program:

// Java program to get current system 
// date and time

//package to class Date class
import java.util.Date;

public class GetSystemDateTimePrg {
  public static void main(String args[]) {
    //creating object of Date class
    Date dt = new Date();
    //printing the date and time 
    System.out.print("Current system date and time is: " + dt.toString());
  }
}

Output

Current system date and time is: Mon Jul 13 20:56:09 IST 2015

Java Date and Time Programs »



Related Programs



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.