ITSourceCode.com

We Exist to Provide 100% Free Source Code and Tutorials

Custom Search

Date and Time

Date and time

To access date and time ,we need java.util package.We cannot display a Date object without first converting it to a String.
The class java.util.Date represents a specific instance in time. It has two constructors:

S.no. Constructor Description
1. Date() Allocate a Date instance with the current time.
2. Date(long millisec) This constructor accepts an argument that equals the number of milliseconds that have elapsed since midnight, January 1, 1970

Some of the important methods of Date class are:

S.no. Method Description
1. long getTime() returns the number of milliseconds since January 1, 1970.
2. String toString() returns a date/time string in local time-zone using the default locale in the format: dow mon dd hh:mm:ss zzz yyyy, where dow is the day of week, mon is the month, zzz is the time zone.


A program to create current date and time in java.

  1. import java.util.Date;
  2. public class Date_disp
  3. { public static void main(String args[])
  4. { Date date = new Date();
  5. System.out.println(date.toString()); }
  6. }
Facebook Comments

Check Your Domain Ranking

Leave a Reply

Your email address will not be published. Required fields are marked *

ITSourceCode.com © 2016 Frontier Theme

Subscribe For Latest Updates

Signup for our newsletter and get notified when we publish new articles for free!