Date and time
To access date and time ,we need java.util package.We cannot display a Date object without first converting it to a String.
The class java.util.Date represents a specific instance in time. It has two constructors:
S.no. Constructor Description
1. Date() Allocate a Date instance with the current time.
2. Date(long millisec) This constructor accepts an argument that equals the number of milliseconds that have elapsed since midnight, January 1, 1970
Some of the important methods of Date class are:
S.no. Method Description
1. long getTime() returns the number of milliseconds since January 1, 1970.
2. String toString() returns a date/time string in local time-zone using the default locale in the format: dow mon dd hh:mm:ss zzz yyyy, where dow is the day of week, mon is the month, zzz is the time zone.
A program to create current date and time in java.