📄 date.java
字号:
10000 + 0, 10000 + 0, 10000 + 0, // GMT/UT/UTC 10000 + 5 * 60, 10000 + 4 * 60, // EST/EDT 10000 + 6 * 60, 10000 + 5 * 60, 10000 + 7 * 60, 10000 + 6 * 60, 10000 + 8 * 60, 10000 + 7 * 60 }; /** * Returns a value that is the result of subtracting 1900 from the * year that contains or begins with the instant in time represented * by this <code>Date</code> object, as interpreted in the local * time zone. * * @return the year represented by this date, minus 1900. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.get(Calendar.YEAR) - 1900</code>. */ public int getYear() { return getField(Calendar.YEAR) - 1900; } /** * Sets the year of this <tt>Date</tt> object to be the specified * value plus 1900. This <code>Date</code> object is modified so * that it represents a point in time within the specified year, * with the month, date, hour, minute, and second the same as * before, as interpreted in the local time zone. (Of course, if * the date was February 29, for example, and the year is set to a * non-leap year, then the new date will be treated as if it were * on March 1.) * * @param year the year value. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.set(Calendar.YEAR, year + 1900)</code>. */ public void setYear(int year) { setField(Calendar.YEAR, year + 1900); } /** * Returns a number representing the month that contains or begins * with the instant in time represented by this <tt>Date</tt> object. * The value returned is between <code>0</code> and <code>11</code>, * with the value <code>0</code> representing January. * * @return the month represented by this date. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.get(Calendar.MONTH)</code>. */ public int getMonth() { return getField(Calendar.MONTH); } /** * Sets the month of this date to the specified value. This * <tt>Date</tt> object is modified so that it represents a point * in time within the specified month, with the year, date, hour, * minute, and second the same as before, as interpreted in the * local time zone. If the date was October 31, for example, and * the month is set to June, then the new date will be treated as * if it were on July 1, because June has only 30 days. * * @param month the month value between 0-11. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>. */ public void setMonth(int month) { setField(Calendar.MONTH, month); } /** * Returns the day of the month represented by this <tt>Date</tt> object. * The value returned is between <code>1</code> and <code>31</code> * representing the day of the month that contains or begins with the * instant in time represented by this <tt>Date</tt> object, as * interpreted in the local time zone. * * @return the day of the month represented by this date. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.get(Calendar.DAY_OF_MONTH)</code>. * @deprecated */ public int getDate() { return getField(Calendar.DATE); } /** * Sets the day of the month of this <tt>Date</tt> object to the * specified value. This <tt>Date</tt> object is modified so that * it represents a point in time within the specified day of the * month, with the year, month, hour, minute, and second the same * as before, as interpreted in the local time zone. If the date * was April 30, for example, and the date is set to 31, then it * will be treated as if it were on May 1, because April has only * 30 days. * * @param date the day of the month value between 1-31. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.set(Calendar.DAY_OF_MONTH, int date)</code>. */ public void setDate(int date) { setField(Calendar.DATE, date); } /** * Returns the day of the week represented by this date. The * returned value (<tt>0</tt> = Sunday, <tt>1</tt> = Monday, * <tt>2</tt> = Tuesday, <tt>3</tt> = Wednesday, <tt>4</tt> = * Thursday, <tt>5</tt> = Friday, <tt>6</tt> = Saturday) * represents the day of the week that contains or begins with * the instant in time represented by this <tt>Date</tt> object, * as interpreted in the local time zone. * * @return the day of the week represented by this date. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.get(Calendar.DAY_OF_WEEK)</code>. */ public int getDay() { return getField(Calendar.DAY_OF_WEEK) - Calendar.SUNDAY; } /** * Returns the hour represented by this <tt>Date</tt> object. The * returned value is a number (<tt>0</tt> through <tt>23</tt>) * representing the hour within the day that contains or begins * with the instant in time represented by this <tt>Date</tt> * object, as interpreted in the local time zone. * * @return the hour represented by this date. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.get(Calendar.HOUR_OF_DAY)</code>. */ public int getHours() { return getField(Calendar.HOUR_OF_DAY); } /** * Sets the hour of this <tt>Date</tt> object to the specified value. * This <tt>Date</tt> object is modified so that it represents a point * in time within the specified hour of the day, with the year, month, * date, minute, and second the same as before, as interpreted in the * local time zone. * * @param hours the hour value. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.set(Calendar.HOUR_OF_DAY, int hours)</code>. */ public void setHours(int hours) { setField(Calendar.HOUR_OF_DAY, hours); } /** * Returns the number of minutes past the hour represented by this date, * as interpreted in the local time zone. * The value returned is between <code>0</code> and <code>59</code>. * * @return the number of minutes past the hour represented by this date. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.get(Calendar.MINUTE)</code>. */ public int getMinutes() { return getField(Calendar.MINUTE); } /** * Sets the minutes of this <tt>Date</tt> object to the specified value. * This <tt>Date</tt> object is modified so that it represents a point * in time within the specified minute of the hour, with the year, month, * date, hour, and second the same as before, as interpreted in the * local time zone. * * @param minutes the value of the minutes. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.set(Calendar.MINUTE, int minutes)</code>. */ public void setMinutes(int minutes) { setField(Calendar.MINUTE, minutes); } /** * Returns the number of seconds past the minute represented by this date. * The value returned is between <code>0</code> and <code>61</code>. The * values <code>60</code> and <code>61</code> can only occur on those * Java Virtual Machines that take leap seconds into account. * * @return the number of seconds past the minute represented by this date. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.get(Calendar.SECOND)</code>. */ public int getSeconds() { return getField(Calendar.SECOND); } /** * Sets the seconds of this <tt>Date</tt> to the specified value. * This <tt>Date</tt> object is modified so that it represents a * point in time within the specified second of the minute, with * the year, month, date, hour, and minute the same as before, as * interpreted in the local time zone. * * @param seconds the seconds value. * @see java.util.Calendar * @deprecated As of JDK version 1.1, * replaced by <code>Calendar.set(Calendar.SECOND, int seconds)</code>. */ public void setSeconds(int seconds) { setField(Calendar.SECOND, seconds); } /** * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this <tt>Date</tt> object. * * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT * represented by this date. */ public long getTime() { return getTimeImpl(); } private final long getTimeImpl() { return (cal == null) ? fastTime : cal.getTimeInMillis(); } /** * Sets this <tt>Date</tt> object to represent a point in time that is * <tt>time</tt> milliseconds after January 1, 1970 00:00:00 GMT. * * @param time the number of milliseconds. */ public void setTime(long time) { if (cal == null) { fastTime = time; } else { cal.setTimeInMillis(time); } } /** * Tests if this date is before the specified date. * * @param when a date. * @return <code>true</code> if and only if the instant of time * represented by this <tt>Date</tt> object is strictly * earlier than the instant represented by <tt>when</tt>; * <code>false</code> otherwise. */ public boolean before(Date when) { return getTime() < when.getTime(); } /** * Tests if this date is after the specified date. * * @param when a date. * @return <code>true</code> if and only if the instant represented * by this <tt>Date</tt> object is strictly later than the * instant represented by <tt>when</tt>; * <code>false</code> otherwise. */ public boolean after(Date when) { return getTime() > when.getTime(); } /** * Compares two dates for equality. * The result is <code>true</code> if and only if the argument is * not <code>null</code> and is a <code>Date</code> object that * represents the same point in time, to the millisecond, as this object. * <p> * Thus, two <code>Date</code> objects are equal if and only if the * <code>getTime</code> method returns the same <code>long</code> * value for both. * * @param obj the object to compare with. * @return <code>true</code> if the objects are the same; * <code>false</code> otherwise. * @see java.util.Date#getTime() */ public boolean equals(Object obj) { return obj instanceof Date && getTime() == ((Date) obj).getTime(); } /** * Compares two Dates for ordering.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -