java date

Java Date
       In Java Date class available in java.util package, this class encapsulates the current date and time. We can also customize  the date according to our requirements. 

This classes are important for dealing with date in java (import any one of class from this).
java.util.Date class
java.sql.Date class
java.text.DateFormat class
java.util.Calendar class
java.util.GregorianCalendar class
java.text.SimpleDateFormat class
java.sql.Time class
java.util.TimeZone class
java.sql.Timestamp class

Java Program:

import java.text.SimpleDateFormat;
import java.util.Date;
public class DateDemo {

       public static void main(String[] args) {
       Date da = new java.util.Date();
      
      System.out.println("default date "+da);
      
      SimpleDateFormat date = new  SimpleDateFormat("yyyy.MMMMMM.dd G 'at' HH:mm:ss z");
      System.out.println(date.format(da));
      
                }

}

Interview Question:

Write a sample program to get the date in java program?
Which classes needed to import to get the date?


EmoticonEmoticon