Home Java Java-get-example Get Time Now



Get Time Now
Posted on: November 5, 2008 at 12:00 AM
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

Related Tags for Get Time Now:
javacclassormtextantdateformattingformtimeiosedformattracnumbermessagepackageabstractlocallikeiftexfortoinformationciexteilitbstrderivedliusepeimfrominrminfocalasstamnttrsagecajpackclesspecagemillisecondlocmeacksssaspessbstatpacrackisinstanthainfimellivandactstrspecificsaxtvattssrithcondavst.textabatihatinforminformatmindonomo


More Tutorials from this section

Ask Questions?    Discuss: Get Time Now  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.