Home Java Java-get-example Get Time Now
Questions:Ask|Latest


 
 

Share on Google+Share on Google+

Get Time Now

Advertisement
Format is an abstract class that is used for formatting local-sensitive information like date, number and message.

Get Time Now

     

Format is an abstract class that is used for formatting local-sensitive information like  date, number and message. The Format class derived from the package  java.text.format. The Date class is used to a specific instant time in millisecond time.

Understand with Example

In this Tutorial we want to describe you a code that helps you to describe Get Time Now. For this we have a class name Get Time Now. Inside the main method we declare a  String variable s,Format formatter and  instantiate date class. The Simple Date Format display the time in a specific format as passed in argument  of variable formatter. The variable formatter call a format method ( ) and pass the date object as argument ,that returns you the current Time in a specified format and store in a string variable, The System.out.println prints the current time from string variable 's'.

Date date = new Date( )   -   This is used to instantiate the date class and allocate the memory to a date object, such that it represent the time allocated to it in the nearest millisecond.

GetTimeNow.java


import java.util.*;
import java.text.*;

public class GetTimeNow {

  public static void main(String args[]) {

  String s;
  Format formatter;
  Date date = new Date();

  formatter = new SimpleDateFormat("hh:mm:ss");
  s = formatter.format(date);
  System.out.println("Time : "+s);
  }
}

Output
Time : 03:34:34
Download code
Advertisements

Liked it!  Share this Tutorial


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: November 5, 2008

Ask Questions?    Discuss: Get Time Now  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments
DMCA.com