Write a JAVA program to get current date and time in the following format :, Current Year is : 2007, Current Month is : 12, Current Date is : 25, Current Hour in 12 hour format is : 6, Current Hour in 24 hour format is : 18, Current Minute is : 28, Current Second is : 54, Current Millisecond is : 797, Current full date time is : 12-25-2007 18:28:54.797
import java.util.*;
import java.text.*;
class DateExample
{
public static void main(String[] args)
{
Date date=new Date();
String str[]={"Current Year is: ","Current Month is: ","Current Date is: ","Current Hour in 12 hour format is: ","Current Hour in 24 hour format is :","Current Minute is: ","Current Second is: ","Current Millisecond is: ","Current full date time is: "};
String formats[]={"yyyy","MM","dd","HH","k","mm","ss","SS","dd-MM-yyyy k:mm:ss.SS"};
for(int i=0;i<formats.length;i++){
SimpleDateFormat sdf=new SimpleDateFormat(formats[i]);
String d=sdf.format(date);
System.out.println(str[i]+d);
}
}
}