Java programming: the Date object

The tutor briefly describes handling the date in Java.

Being object oriented, Java makes the date an object. You can create a date object with the line

Date dat0=new Date();

The following application shows how to output the date in Java. One interesting method it contains is getTime(), which produces the number of seconds since 00:00:00 on Jan 1, 1970.

class DateTest{
public static void main(String[] args){
Date dat0=new Date();
String datestring=dat0.toString();//converts date to a string

System.out.println(“\nThe date is “+ datestring +”\n”);

System.out.println(“The time since Jan 1, 1970, in milliseconds, is “+dat0.getTime()+”\n”);

}//end of main()
}//end of class

For instructions about compiling and running the file, you might read my article here.

HTH:)

Source:

Java Docs

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Leave a Reply