Program to display current date and time in java:
package kuw_ord.test;
import java.util.*;
public class date
{
public static void main(String[] args)
{
Date bs=new Date();
System.out.println(bs.toString());
}
}
Date is the class in java that is available in java.util package. This class contains current date and time.In this program what basically doing is that i am creating the object of Date class that is bs. The object is created by using new keyword that allocate the memory to the bs object. After that the current object created is converted into String by using toString() method. It will create the date into String format.
The output of the program is:
FIG: Output displaying current date and time |
Also you can check the blog http://javarevisited.blogspot.in/2015/03/20-examples-of-date-and-time-api-from-Java8.html
No comments:
Post a Comment