Switch to full style
Java2 codes,problems ,discussions and solutions are here
Post a reply

How to get system time in java

Wed Sep 07, 2011 3:12 pm

HOW TO GET AN SYSTEMTIME IN JAVACODE



Re: DOUBT

Thu Sep 08, 2011 10:05 pm

Code:

 
package TextAreaExample
;

import java.text.SimpleDateFormat;
import java.util.Calendar;


public class ExampleClass {

    public static void main(String[] args) {

        // Create a calendar instance with system current time.
        Calendar calendar = Calendar.getInstance();

        // Formating the time .
        SimpleDateFormat dateFormat = new SimpleDateFormat("H:mm:ss:SSS");
        System.out.println("Current Time(H:mm:ss:SSS) :" + dateFormat.format(calendar.getTime()));

        // Another Format
        dateFormat = new SimpleDateFormat("yyyyMMdd");
        System.out.println("Current Time(yyyyMMdd):" + dateFormat.format(calendar.getTime()));

        // Custom Formating.
        int currentHour = calendar.get(Calendar.HOUR);
        int currentMinute = calendar.get(Calendar.MINUTE);
        int currentSeconds = calendar.get(Calendar.SECOND);

        String amOrpm="";

        if(calendar.get(Calendar.AM)==1){
            amOrpm="PM";
        }else
        {
            amOrpm="AM";
        }

        System.out.println("H:"+currentHour+",m:"+currentMinute+",s:"+currentSeconds+":"+amOrpm);
        
    
}
}
 


Post a reply
  Related Posts  to : How to get system time in java
 current system time     -  
 Java script time parameter     -  
 Default Expire time for Session JAVA     -  
 mail system in java     -  
 Abbreviations System java     -  
 Java Websphere Portal Developer Full-time position in IL     -  
 Customer Controls System in Java     -  
 chat system project in java using netbeans     -  
 code for online payment system in java     -  
 how to create a photo management system using java     -  

Topic Tags

Java Time