Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chandru
Quries
1 Answer(s)      3 years and 5 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


Advertisement
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 Tutorials/Questions & Answers:
sql quries
sql quries  i want basic sql quries please provide
Advertisements
uploading image in the form
they logged into the screen. Im using Orcale database(sql quries to check
CHECK WHICH NO IS GREATER IN 4 NO'S
chaudhary(+919261377137) if you want to ask any quries then contact me or email
Advertisements
 

 

 

DMCA.com