Sunday, December 21, 2008

Java Date

Date and time, An essential factor in a program for implementing many concepts at real-time. Java provides a special class – date Class in the java.util Package (sort of catch-all for handy utilities).

Date provides methods for examining and manipulating date and time. Time in java is measured in milliseconds since January 1, 1970. Java attempts to handle time from the system with which it is interfacing. UTC is coordinated Universal Time, which seems to be the worldwide standard.

Note : In the date class, dates before January 1, 1970 are generally not usable.

List of the methods to see full scope of the Date class:

Methods

Purpose

UTC(int, int, int, int, int)

Calculates a UTC value from YMDHMS

after(Date)

check whether this date comes after the specified date

before(Date)

Checks whether this date comes before the specified date

equals(Object)

Compares this object against specified object

getDate()

Returns the day of the month

getDay()

Returns the day of the week

getHours()

Returns the hour

getMinutes()

Returns the minute

getMonth()

Returns the month

getSeconds()

Returns the seconds

getTime()

Returns the time in milliseconds since the epoch

getTimezoneOffset()

Returns the time zone offset in minutes for the current locale that is appropriate for this time

getYear()

Returns the year after 1900

hashCode()

Compares a number that is used when storing objects in hash tables.

parse(String)

given a string representing a time, parses it and returns the time value.

setDate(int)

Sets the date

setHours(int)

Sets the hour

setMinutes(int)

Sets the minute

setMonth(int)

Sets the month

setSecondsint()

Sets the seconds

setTime(int)

Sets the time

setYear(int)

Sets the year

toGMTString()

Converts a date to string object, using the internet GMT conversions.

toLocalString()

Converts a date to string object, using the locale conversions.

toString()

Converts a date to string object, using UNIX conversions.

It is important to remember that months start with 0, which is January, and end with 11, which is December. The days of the week also start with 0, which is Sunday, and go through 6, which is Saturday. Dates of the month are normal.

0 comments: