Web | This Site

Java Basics Examples
Java Tutorial
Java Useful Resources
Selected Reading
© 2011 TutorialsPoint.COM

| Home |  | References |  | Discussion Forums |  | About TP

# Java Examples - Displaying current time

## Problem Description:

How to display hour and minute ?

## Solution:

This example demonstrates how to display the hour and minute of that moment by using Calender.getInstance() of Calender class.

    import java.util.Calendar;
    import java.util.Formatter;

    public class MainClass{
       public static void main(String args[]){
          Formatter fmt = new Formatter();
          Calendar cal = Calendar.getInstance();
          fmt = new Formatter();
          fmt.format("%tl:%tM", cal, cal);
          System.out.println(fmt);
       }
    }

## Result:

The above code sample will produce the following result.The result will chenge depending upon the current system time.

    03:20

Advertisement

Online Image Processing

Indian Baby Names