All About Class Date in Java



Class Date is intended to reflected UTC(Universal Time Coordinate) time,but it may not do so exactly as it depends on host environment of the java virtual machine.All modern operating system assume that one day =24 hours =24*60*60 seconds=86400 seconds in all Date related cases. In UTC,however about once every year or two there is an extra second called 'leap second'.The leap second is always added as the last second of the day and always on December 31st or June 30th.Most computer clocks are not accurate enough to be able to keep second distinction.
The class Date provides an abstraction of dates and times. Dates may be constructed from the following six components..

  • Year
  • Month 
  • Date(day of the month)
  • Hour
  • Minute
  • Seconds.
Also the day of the week can also be extracted from date. Dates may be also compared and converted to readable String form.A date is represented to a precision of one millisecond.Some computer standards are defined in terms of GMT(Greenwich Mean Time) which is equivalent to UT-Universal Time . GMT is the civil name for the standard.UT is the scientific name for the same standard. UTC is based on an atomic clock and UT is based on an astronomical observation which is for all practical purpose.They both does not represent same time .It is due to the fact that earth's rotation is not uniform,it slows down and speeds up in complicated way.As a result UT does not flow uniformly. Leap seconds are introduced as needed into UTC so as to keep UTC up to date.One second of UT1,which is another version of UT with certain correction applied is also available. There are several other time and date system as well.
The time scale used by GPS(satellite based Global positioning System) is synchronized to UTC but not adjusted for leap seconds.
In date the below component exists
Year-y is represented by integer like y-2018
Month is represented by an integer from 0 to 11.0 being January and 11 being December.
Date(day of the month) is represented by an integer from 1 to 31
Hours are represented by an integer from 0 to 23.Thus hours from midnight 1AM is hour 0 and the hours from noon 1PM is hour 12.
Minute is represented by an integer from 0 to 59.
Second is represented by an integer from 0 to 60. The value 60 occurs only for Leap seconds and even then only java implementation that actually track leap seconds correctly.

The class structure of Date is as follows:

public class java.util.Date extends java.lang.Object{
//constructors
public Date();
//allocates a Date Object and initializes it,so that it represents the time at which it was allocated 
//measures to the nearest millisecond.
public Date(int year,int month,int date);
//allocates a Date Object and initializes it,so that it represents midnight,local time at the beginning
//of the day specified by the year,month and date arguments.
public Date(int year,int month,int date,int hrs,int min);
//allocates a Date Object and initializes it,so that it represents midnight,local time at the beginning
//of the day specified by the year,month,date,hrs and min arguments.
public Date(int year,int month,int date,int hrs,int min,int sec);
//allocates a Date Object and initializes it,so that it represents midnight,local time at the beginning
//of the day specified by the year,month,date,hrs,min an sec arguments.
public Date(long Date);
//allocates a Date object and initializes it to represent the specified number of milliseconds since 
//January 1,1970,00:00:00 GMT
public Date(String s);
//allocates a Date object and initializes it to represent the date and time indicating by String s which is 
//interpreted as if by the parse method.
//Method
public boolean after(Date when);
public boolean before(Date when);
public boolean equals(Date when);
public int getDate();
public int getDay();
public int getHours();
public int getMinutes();
public int getSeconds();
public int getTimezoneOffset();
public int getYear();
public int hashCode();
public long getTime();
public static long parse(String s);
public static long UTC(int year,int month,int date,int hrs,int min,int sec);
public String toString();
public String toLocaleString();
public String toGMTString();
public void setDate(int date);
public void setHours(int hours);
public void setMinutes(int minutes);
public void setMonth(int month);
public void setSeconds(int seconds);
public void setTime(long time);
public void setYear(int year);
}
 
All About Class Date in Java All About Class Date in Java Reviewed by Animesh Chatterjee on October 11, 2018 Rating: 5

No comments:

Powered by Blogger.