OCJP

Date and Time in Java

Java provides the Date class available in java.util package, this class contains Date and Time related functions.

For example following program demonstrates how object of Date class can be created.

import java.util.Date;
public class DateDemo {

   public static void main(String args[]) {
      
      Date date = new Date(); //Created object of Date Class

      // Converted to String and Displayed the same
      System.out.println(date.toString());
   }
}

Output:

It will show current date and time of the system.

Leave a Reply

Your email address will not be published. Required fields are marked *


× How can I help you?