Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
Get Time And Date 
 

The Class Date provides you a specific instant in time( millisecond) precision. This class enabled you to interprets allowed dates as year, month, day, hour, minute, and second values and date formatting and parsing of date string.

 

Get Time And Date

                         

The Class  Date provides you  a specific instant in time( millisecond) precision. This class enabled you to interprets  allowed  dates as year, month, day, hour, minute, and second values and date formatting and parsing of date string.

Understand with Example

In this Tutorial we want to describe you a code that helps you in understanding in a Getting Time and Date. For this we have a class 'GetTimeAndDate'.Inside the main method we declared a string variable, formatter and instantiate a date class.

1)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.

2)SimpleDateFormat- is a  formatting concrete class that helps you in parsing date in a locale-sensitive manner. This allows you to format (date -> text), parsing (text -> date), and normalization.

3)format(date) -This method return you a formatted object to a string and stored in a string variable s.

Finally the System.out .println print the Date, Time and date-time altogether.

GetTimeAndDate.java

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

public class GetTimeAndDate {

    public static void main(String args[]) {

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

        formatter = new SimpleDateFormat("dd/MMM/yyyy");
        s = formatter.format(date);
        System.out.println("Date : " + s);

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

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

Output
Date : 03/Nov/2008
Time : 04:28:52 PM
Time : 03 November 2008 16:28:52
Download code

                         

» View all related tutorials
Related Tags: c class ant help property get tutorial name ria this for to e des pe in as sta m nt

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

thanks for giving the code. it is very useful to every one

Posted by anita on Tuesday, 12.16.08 @ 05:27am | #82821

Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.