Total members 11893 |It is currently Tue Nov 05, 2024 2:36 pm Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





HOW TO GET AN SYSTEMTIME IN JAVACODE




Author:

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


_________________
M. S. Rakha, Ph.D.
Queen's University
Canada


Author:
Mastermind
User avatar Posts: 2715
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 

  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     -  
 how to create a photo management system using java     -  
 chat system project in java using netbeans     -  
 code for online payment system in java     -  



Topic Tags

Java Time
cron





Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com