chandru
Quries
1 Answer(s)      a year and 9 months ago
Posted in : Java Beginners

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

View Answers

August 4, 2011 at 11:23 AM


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);
        }
    }
}









Related Pages:
sql quries
sql quries  i want basic sql quries please provide
CHECK WHICH NO IS GREATER IN 4 NO'S
chaudhary(+919261377137) if you want to ask any quries then contact me or email

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.