PageRenderTime 62ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 0ms

/java-1.7.0-openjdk/openjdk/jdk/src/share/classes/java/util/Date.java

#
Java | 1331 lines | 533 code | 59 blank | 739 comment | 185 complexity | b34b0a633fb01c3c9778174f679c95b9 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause-No-Nuclear-License-2014, LGPL-3.0, LGPL-2.0

Large files files are truncated, but you can click here to view the full file

  1. /*
  2. * Copyright (c) 1994, 2010, Oracle and/or its affiliates. All rights reserved.
  3. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  4. *
  5. * This code is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License version 2 only, as
  7. * published by the Free Software Foundation. Oracle designates this
  8. * particular file as subject to the "Classpath" exception as provided
  9. * by Oracle in the LICENSE file that accompanied this code.
  10. *
  11. * This code is distributed in the hope that it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  14. * version 2 for more details (a copy is included in the LICENSE file that
  15. * accompanied this code).
  16. *
  17. * You should have received a copy of the GNU General Public License version
  18. * 2 along with this work; if not, write to the Free Software Foundation,
  19. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20. *
  21. * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22. * or visit www.oracle.com if you need additional information or have any
  23. * questions.
  24. */
  25. package java.util;
  26. import java.text.DateFormat;
  27. import java.io.IOException;
  28. import java.io.ObjectOutputStream;
  29. import java.io.ObjectInputStream;
  30. import java.lang.ref.SoftReference;
  31. import sun.util.calendar.BaseCalendar;
  32. import sun.util.calendar.CalendarDate;
  33. import sun.util.calendar.CalendarSystem;
  34. import sun.util.calendar.CalendarUtils;
  35. import sun.util.calendar.Era;
  36. import sun.util.calendar.Gregorian;
  37. import sun.util.calendar.ZoneInfo;
  38. /**
  39. * The class <code>Date</code> represents a specific instant
  40. * in time, with millisecond precision.
  41. * <p>
  42. * Prior to JDK&nbsp;1.1, the class <code>Date</code> had two additional
  43. * functions. It allowed the interpretation of dates as year, month, day, hour,
  44. * minute, and second values. It also allowed the formatting and parsing
  45. * of date strings. Unfortunately, the API for these functions was not
  46. * amenable to internationalization. As of JDK&nbsp;1.1, the
  47. * <code>Calendar</code> class should be used to convert between dates and time
  48. * fields and the <code>DateFormat</code> class should be used to format and
  49. * parse date strings.
  50. * The corresponding methods in <code>Date</code> are deprecated.
  51. * <p>
  52. * Although the <code>Date</code> class is intended to reflect
  53. * coordinated universal time (UTC), it may not do so exactly,
  54. * depending on the host environment of the Java Virtual Machine.
  55. * Nearly all modern operating systems assume that 1&nbsp;day&nbsp;=
  56. * 24&nbsp;&times;&nbsp;60&nbsp;&times;&nbsp;60&nbsp;= 86400 seconds
  57. * in all cases. In UTC, however, about once every year or two there
  58. * is an extra second, called a "leap second." The leap
  59. * second is always added as the last second of the day, and always
  60. * on December 31 or June 30. For example, the last minute of the
  61. * year 1995 was 61 seconds long, thanks to an added leap second.
  62. * Most computer clocks are not accurate enough to be able to reflect
  63. * the leap-second distinction.
  64. * <p>
  65. * Some computer standards are defined in terms of Greenwich mean
  66. * time (GMT), which is equivalent to universal time (UT). GMT is
  67. * the "civil" name for the standard; UT is the
  68. * "scientific" name for the same standard. The
  69. * distinction between UTC and UT is that UTC is based on an atomic
  70. * clock and UT is based on astronomical observations, which for all
  71. * practical purposes is an invisibly fine hair to split. Because the
  72. * earth's rotation is not uniform (it slows down and speeds up
  73. * in complicated ways), UT does not always flow uniformly. Leap
  74. * seconds are introduced as needed into UTC so as to keep UTC within
  75. * 0.9 seconds of UT1, which is a version of UT with certain
  76. * corrections applied. There are other time and date systems as
  77. * well; for example, the time scale used by the satellite-based
  78. * global positioning system (GPS) is synchronized to UTC but is
  79. * <i>not</i> adjusted for leap seconds. An interesting source of
  80. * further information is the U.S. Naval Observatory, particularly
  81. * the Directorate of Time at:
  82. * <blockquote><pre>
  83. * <a href=http://tycho.usno.navy.mil>http://tycho.usno.navy.mil</a>
  84. * </pre></blockquote>
  85. * <p>
  86. * and their definitions of "Systems of Time" at:
  87. * <blockquote><pre>
  88. * <a href=http://tycho.usno.navy.mil/systime.html>http://tycho.usno.navy.mil/systime.html</a>
  89. * </pre></blockquote>
  90. * <p>
  91. * In all methods of class <code>Date</code> that accept or return
  92. * year, month, date, hours, minutes, and seconds values, the
  93. * following representations are used:
  94. * <ul>
  95. * <li>A year <i>y</i> is represented by the integer
  96. * <i>y</i>&nbsp;<code>-&nbsp;1900</code>.
  97. * <li>A month is represented by an integer from 0 to 11; 0 is January,
  98. * 1 is February, and so forth; thus 11 is December.
  99. * <li>A date (day of month) is represented by an integer from 1 to 31
  100. * in the usual manner.
  101. * <li>An hour is represented by an integer from 0 to 23. Thus, the hour
  102. * from midnight to 1 a.m. is hour 0, and the hour from noon to 1
  103. * p.m. is hour 12.
  104. * <li>A minute is represented by an integer from 0 to 59 in the usual manner.
  105. * <li>A second is represented by an integer from 0 to 61; the values 60 and
  106. * 61 occur only for leap seconds and even then only in Java
  107. * implementations that actually track leap seconds correctly. Because
  108. * of the manner in which leap seconds are currently introduced, it is
  109. * extremely unlikely that two leap seconds will occur in the same
  110. * minute, but this specification follows the date and time conventions
  111. * for ISO C.
  112. * </ul>
  113. * <p>
  114. * In all cases, arguments given to methods for these purposes need
  115. * not fall within the indicated ranges; for example, a date may be
  116. * specified as January 32 and is interpreted as meaning February 1.
  117. *
  118. * @author James Gosling
  119. * @author Arthur van Hoff
  120. * @author Alan Liu
  121. * @see java.text.DateFormat
  122. * @see java.util.Calendar
  123. * @see java.util.TimeZone
  124. * @since JDK1.0
  125. */
  126. public class Date
  127. implements java.io.Serializable, Cloneable, Comparable<Date>
  128. {
  129. private static final BaseCalendar gcal =
  130. CalendarSystem.getGregorianCalendar();
  131. private static BaseCalendar jcal;
  132. private transient long fastTime;
  133. /*
  134. * If cdate is null, then fastTime indicates the time in millis.
  135. * If cdate.isNormalized() is true, then fastTime and cdate are in
  136. * synch. Otherwise, fastTime is ignored, and cdate indicates the
  137. * time.
  138. */
  139. private transient BaseCalendar.Date cdate;
  140. // Initialized just before the value is used. See parse().
  141. private static int defaultCenturyStart;
  142. /* use serialVersionUID from modified java.util.Date for
  143. * interoperability with JDK1.1. The Date was modified to write
  144. * and read only the UTC time.
  145. */
  146. private static final long serialVersionUID = 7523967970034938905L;
  147. /**
  148. * Allocates a <code>Date</code> object and initializes it so that
  149. * it represents the time at which it was allocated, measured to the
  150. * nearest millisecond.
  151. *
  152. * @see java.lang.System#currentTimeMillis()
  153. */
  154. public Date() {
  155. this(System.currentTimeMillis());
  156. }
  157. /**
  158. * Allocates a <code>Date</code> object and initializes it to
  159. * represent the specified number of milliseconds since the
  160. * standard base time known as "the epoch", namely January 1,
  161. * 1970, 00:00:00 GMT.
  162. *
  163. * @param date the milliseconds since January 1, 1970, 00:00:00 GMT.
  164. * @see java.lang.System#currentTimeMillis()
  165. */
  166. public Date(long date) {
  167. fastTime = date;
  168. }
  169. /**
  170. * Allocates a <code>Date</code> object and initializes it so that
  171. * it represents midnight, local time, at the beginning of the day
  172. * specified by the <code>year</code>, <code>month</code>, and
  173. * <code>date</code> arguments.
  174. *
  175. * @param year the year minus 1900.
  176. * @param month the month between 0-11.
  177. * @param date the day of the month between 1-31.
  178. * @see java.util.Calendar
  179. * @deprecated As of JDK version 1.1,
  180. * replaced by <code>Calendar.set(year + 1900, month, date)</code>
  181. * or <code>GregorianCalendar(year + 1900, month, date)</code>.
  182. */
  183. @Deprecated
  184. public Date(int year, int month, int date) {
  185. this(year, month, date, 0, 0, 0);
  186. }
  187. /**
  188. * Allocates a <code>Date</code> object and initializes it so that
  189. * it represents the instant at the start of the minute specified by
  190. * the <code>year</code>, <code>month</code>, <code>date</code>,
  191. * <code>hrs</code>, and <code>min</code> arguments, in the local
  192. * time zone.
  193. *
  194. * @param year the year minus 1900.
  195. * @param month the month between 0-11.
  196. * @param date the day of the month between 1-31.
  197. * @param hrs the hours between 0-23.
  198. * @param min the minutes between 0-59.
  199. * @see java.util.Calendar
  200. * @deprecated As of JDK version 1.1,
  201. * replaced by <code>Calendar.set(year + 1900, month, date,
  202. * hrs, min)</code> or <code>GregorianCalendar(year + 1900,
  203. * month, date, hrs, min)</code>.
  204. */
  205. @Deprecated
  206. public Date(int year, int month, int date, int hrs, int min) {
  207. this(year, month, date, hrs, min, 0);
  208. }
  209. /**
  210. * Allocates a <code>Date</code> object and initializes it so that
  211. * it represents the instant at the start of the second specified
  212. * by the <code>year</code>, <code>month</code>, <code>date</code>,
  213. * <code>hrs</code>, <code>min</code>, and <code>sec</code> arguments,
  214. * in the local time zone.
  215. *
  216. * @param year the year minus 1900.
  217. * @param month the month between 0-11.
  218. * @param date the day of the month between 1-31.
  219. * @param hrs the hours between 0-23.
  220. * @param min the minutes between 0-59.
  221. * @param sec the seconds between 0-59.
  222. * @see java.util.Calendar
  223. * @deprecated As of JDK version 1.1,
  224. * replaced by <code>Calendar.set(year + 1900, month, date,
  225. * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
  226. * month, date, hrs, min, sec)</code>.
  227. */
  228. @Deprecated
  229. public Date(int year, int month, int date, int hrs, int min, int sec) {
  230. int y = year + 1900;
  231. // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
  232. if (month >= 12) {
  233. y += month / 12;
  234. month %= 12;
  235. } else if (month < 0) {
  236. y += CalendarUtils.floorDivide(month, 12);
  237. month = CalendarUtils.mod(month, 12);
  238. }
  239. BaseCalendar cal = getCalendarSystem(y);
  240. cdate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
  241. cdate.setNormalizedDate(y, month + 1, date).setTimeOfDay(hrs, min, sec, 0);
  242. getTimeImpl();
  243. cdate = null;
  244. }
  245. /**
  246. * Allocates a <code>Date</code> object and initializes it so that
  247. * it represents the date and time indicated by the string
  248. * <code>s</code>, which is interpreted as if by the
  249. * {@link Date#parse} method.
  250. *
  251. * @param s a string representation of the date.
  252. * @see java.text.DateFormat
  253. * @see java.util.Date#parse(java.lang.String)
  254. * @deprecated As of JDK version 1.1,
  255. * replaced by <code>DateFormat.parse(String s)</code>.
  256. */
  257. @Deprecated
  258. public Date(String s) {
  259. this(parse(s));
  260. }
  261. /**
  262. * Return a copy of this object.
  263. */
  264. public Object clone() {
  265. Date d = null;
  266. try {
  267. d = (Date)super.clone();
  268. if (cdate != null) {
  269. d.cdate = (BaseCalendar.Date) cdate.clone();
  270. }
  271. } catch (CloneNotSupportedException e) {} // Won't happen
  272. return d;
  273. }
  274. /**
  275. * Determines the date and time based on the arguments. The
  276. * arguments are interpreted as a year, month, day of the month,
  277. * hour of the day, minute within the hour, and second within the
  278. * minute, exactly as for the <tt>Date</tt> constructor with six
  279. * arguments, except that the arguments are interpreted relative
  280. * to UTC rather than to the local time zone. The time indicated is
  281. * returned represented as the distance, measured in milliseconds,
  282. * of that time from the epoch (00:00:00 GMT on January 1, 1970).
  283. *
  284. * @param year the year minus 1900.
  285. * @param month the month between 0-11.
  286. * @param date the day of the month between 1-31.
  287. * @param hrs the hours between 0-23.
  288. * @param min the minutes between 0-59.
  289. * @param sec the seconds between 0-59.
  290. * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT for
  291. * the date and time specified by the arguments.
  292. * @see java.util.Calendar
  293. * @deprecated As of JDK version 1.1,
  294. * replaced by <code>Calendar.set(year + 1900, month, date,
  295. * hrs, min, sec)</code> or <code>GregorianCalendar(year + 1900,
  296. * month, date, hrs, min, sec)</code>, using a UTC
  297. * <code>TimeZone</code>, followed by <code>Calendar.getTime().getTime()</code>.
  298. */
  299. @Deprecated
  300. public static long UTC(int year, int month, int date,
  301. int hrs, int min, int sec) {
  302. int y = year + 1900;
  303. // month is 0-based. So we have to normalize month to support Long.MAX_VALUE.
  304. if (month >= 12) {
  305. y += month / 12;
  306. month %= 12;
  307. } else if (month < 0) {
  308. y += CalendarUtils.floorDivide(month, 12);
  309. month = CalendarUtils.mod(month, 12);
  310. }
  311. int m = month + 1;
  312. BaseCalendar cal = getCalendarSystem(y);
  313. BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null);
  314. udate.setNormalizedDate(y, m, date).setTimeOfDay(hrs, min, sec, 0);
  315. // Use a Date instance to perform normalization. Its fastTime
  316. // is the UTC value after the normalization.
  317. Date d = new Date(0);
  318. d.normalize(udate);
  319. return d.fastTime;
  320. }
  321. /**
  322. * Attempts to interpret the string <tt>s</tt> as a representation
  323. * of a date and time. If the attempt is successful, the time
  324. * indicated is returned represented as the distance, measured in
  325. * milliseconds, of that time from the epoch (00:00:00 GMT on
  326. * January 1, 1970). If the attempt fails, an
  327. * <tt>IllegalArgumentException</tt> is thrown.
  328. * <p>
  329. * It accepts many syntaxes; in particular, it recognizes the IETF
  330. * standard date syntax: "Sat, 12 Aug 1995 13:30:00 GMT". It also
  331. * understands the continental U.S. time-zone abbreviations, but for
  332. * general use, a time-zone offset should be used: "Sat, 12 Aug 1995
  333. * 13:30:00 GMT+0430" (4 hours, 30 minutes west of the Greenwich
  334. * meridian). If no time zone is specified, the local time zone is
  335. * assumed. GMT and UTC are considered equivalent.
  336. * <p>
  337. * The string <tt>s</tt> is processed from left to right, looking for
  338. * data of interest. Any material in <tt>s</tt> that is within the
  339. * ASCII parenthesis characters <tt>(</tt> and <tt>)</tt> is ignored.
  340. * Parentheses may be nested. Otherwise, the only characters permitted
  341. * within <tt>s</tt> are these ASCII characters:
  342. * <blockquote><pre>
  343. * abcdefghijklmnopqrstuvwxyz
  344. * ABCDEFGHIJKLMNOPQRSTUVWXYZ
  345. * 0123456789,+-:/</pre></blockquote>
  346. * and whitespace characters.<p>
  347. * A consecutive sequence of decimal digits is treated as a decimal
  348. * number:<ul>
  349. * <li>If a number is preceded by <tt>+</tt> or <tt>-</tt> and a year
  350. * has already been recognized, then the number is a time-zone
  351. * offset. If the number is less than 24, it is an offset measured
  352. * in hours. Otherwise, it is regarded as an offset in minutes,
  353. * expressed in 24-hour time format without punctuation. A
  354. * preceding <tt>-</tt> means a westward offset. Time zone offsets
  355. * are always relative to UTC (Greenwich). Thus, for example,
  356. * <tt>-5</tt> occurring in the string would mean "five hours west
  357. * of Greenwich" and <tt>+0430</tt> would mean "four hours and
  358. * thirty minutes east of Greenwich." It is permitted for the
  359. * string to specify <tt>GMT</tt>, <tt>UT</tt>, or <tt>UTC</tt>
  360. * redundantly-for example, <tt>GMT-5</tt> or <tt>utc+0430</tt>.
  361. * <li>The number is regarded as a year number if one of the
  362. * following conditions is true:
  363. * <ul>
  364. * <li>The number is equal to or greater than 70 and followed by a
  365. * space, comma, slash, or end of string
  366. * <li>The number is less than 70, and both a month and a day of
  367. * the month have already been recognized</li>
  368. * </ul>
  369. * If the recognized year number is less than 100, it is
  370. * interpreted as an abbreviated year relative to a century of
  371. * which dates are within 80 years before and 19 years after
  372. * the time when the Date class is initialized.
  373. * After adjusting the year number, 1900 is subtracted from
  374. * it. For example, if the current year is 1999 then years in
  375. * the range 19 to 99 are assumed to mean 1919 to 1999, while
  376. * years from 0 to 18 are assumed to mean 2000 to 2018. Note
  377. * that this is slightly different from the interpretation of
  378. * years less than 100 that is used in {@link java.text.SimpleDateFormat}.
  379. * <li>If the number is followed by a colon, it is regarded as an hour,
  380. * unless an hour has already been recognized, in which case it is
  381. * regarded as a minute.
  382. * <li>If the number is followed by a slash, it is regarded as a month
  383. * (it is decreased by 1 to produce a number in the range <tt>0</tt>
  384. * to <tt>11</tt>), unless a month has already been recognized, in
  385. * which case it is regarded as a day of the month.
  386. * <li>If the number is followed by whitespace, a comma, a hyphen, or
  387. * end of string, then if an hour has been recognized but not a
  388. * minute, it is regarded as a minute; otherwise, if a minute has
  389. * been recognized but not a second, it is regarded as a second;
  390. * otherwise, it is regarded as a day of the month. </ul><p>
  391. * A consecutive sequence of letters is regarded as a word and treated
  392. * as follows:<ul>
  393. * <li>A word that matches <tt>AM</tt>, ignoring case, is ignored (but
  394. * the parse fails if an hour has not been recognized or is less
  395. * than <tt>1</tt> or greater than <tt>12</tt>).
  396. * <li>A word that matches <tt>PM</tt>, ignoring case, adds <tt>12</tt>
  397. * to the hour (but the parse fails if an hour has not been
  398. * recognized or is less than <tt>1</tt> or greater than <tt>12</tt>).
  399. * <li>Any word that matches any prefix of <tt>SUNDAY, MONDAY, TUESDAY,
  400. * WEDNESDAY, THURSDAY, FRIDAY</tt>, or <tt>SATURDAY</tt>, ignoring
  401. * case, is ignored. For example, <tt>sat, Friday, TUE</tt>, and
  402. * <tt>Thurs</tt> are ignored.
  403. * <li>Otherwise, any word that matches any prefix of <tt>JANUARY,
  404. * FEBRUARY, MARCH, APRIL, MAY, JUNE, JULY, AUGUST, SEPTEMBER,
  405. * OCTOBER, NOVEMBER</tt>, or <tt>DECEMBER</tt>, ignoring case, and
  406. * considering them in the order given here, is recognized as
  407. * specifying a month and is converted to a number (<tt>0</tt> to
  408. * <tt>11</tt>). For example, <tt>aug, Sept, april</tt>, and
  409. * <tt>NOV</tt> are recognized as months. So is <tt>Ma</tt>, which
  410. * is recognized as <tt>MARCH</tt>, not <tt>MAY</tt>.
  411. * <li>Any word that matches <tt>GMT, UT</tt>, or <tt>UTC</tt>, ignoring
  412. * case, is treated as referring to UTC.
  413. * <li>Any word that matches <tt>EST, CST, MST</tt>, or <tt>PST</tt>,
  414. * ignoring case, is recognized as referring to the time zone in
  415. * North America that is five, six, seven, or eight hours west of
  416. * Greenwich, respectively. Any word that matches <tt>EDT, CDT,
  417. * MDT</tt>, or <tt>PDT</tt>, ignoring case, is recognized as
  418. * referring to the same time zone, respectively, during daylight
  419. * saving time.</ul><p>
  420. * Once the entire string s has been scanned, it is converted to a time
  421. * result in one of two ways. If a time zone or time-zone offset has been
  422. * recognized, then the year, month, day of month, hour, minute, and
  423. * second are interpreted in UTC and then the time-zone offset is
  424. * applied. Otherwise, the year, month, day of month, hour, minute, and
  425. * second are interpreted in the local time zone.
  426. *
  427. * @param s a string to be parsed as a date.
  428. * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
  429. * represented by the string argument.
  430. * @see java.text.DateFormat
  431. * @deprecated As of JDK version 1.1,
  432. * replaced by <code>DateFormat.parse(String s)</code>.
  433. */
  434. @Deprecated
  435. public static long parse(String s) {
  436. int year = Integer.MIN_VALUE;
  437. int mon = -1;
  438. int mday = -1;
  439. int hour = -1;
  440. int min = -1;
  441. int sec = -1;
  442. int millis = -1;
  443. int c = -1;
  444. int i = 0;
  445. int n = -1;
  446. int wst = -1;
  447. int tzoffset = -1;
  448. int prevc = 0;
  449. syntax:
  450. {
  451. if (s == null)
  452. break syntax;
  453. int limit = s.length();
  454. while (i < limit) {
  455. c = s.charAt(i);
  456. i++;
  457. if (c <= ' ' || c == ',')
  458. continue;
  459. if (c == '(') { // skip comments
  460. int depth = 1;
  461. while (i < limit) {
  462. c = s.charAt(i);
  463. i++;
  464. if (c == '(') depth++;
  465. else if (c == ')')
  466. if (--depth <= 0)
  467. break;
  468. }
  469. continue;
  470. }
  471. if ('0' <= c && c <= '9') {
  472. n = c - '0';
  473. while (i < limit && '0' <= (c = s.charAt(i)) && c <= '9') {
  474. n = n * 10 + c - '0';
  475. i++;
  476. }
  477. if (prevc == '+' || prevc == '-' && year != Integer.MIN_VALUE) {
  478. // timezone offset
  479. if (n < 24)
  480. n = n * 60; // EG. "GMT-3"
  481. else
  482. n = n % 100 + n / 100 * 60; // eg "GMT-0430"
  483. if (prevc == '+') // plus means east of GMT
  484. n = -n;
  485. if (tzoffset != 0 && tzoffset != -1)
  486. break syntax;
  487. tzoffset = n;
  488. } else if (n >= 70)
  489. if (year != Integer.MIN_VALUE)
  490. break syntax;
  491. else if (c <= ' ' || c == ',' || c == '/' || i >= limit)
  492. // year = n < 1900 ? n : n - 1900;
  493. year = n;
  494. else
  495. break syntax;
  496. else if (c == ':')
  497. if (hour < 0)
  498. hour = (byte) n;
  499. else if (min < 0)
  500. min = (byte) n;
  501. else
  502. break syntax;
  503. else if (c == '/')
  504. if (mon < 0)
  505. mon = (byte) (n - 1);
  506. else if (mday < 0)
  507. mday = (byte) n;
  508. else
  509. break syntax;
  510. else if (i < limit && c != ',' && c > ' ' && c != '-')
  511. break syntax;
  512. else if (hour >= 0 && min < 0)
  513. min = (byte) n;
  514. else if (min >= 0 && sec < 0)
  515. sec = (byte) n;
  516. else if (mday < 0)
  517. mday = (byte) n;
  518. // Handle two-digit years < 70 (70-99 handled above).
  519. else if (year == Integer.MIN_VALUE && mon >= 0 && mday >= 0)
  520. year = n;
  521. else
  522. break syntax;
  523. prevc = 0;
  524. } else if (c == '/' || c == ':' || c == '+' || c == '-')
  525. prevc = c;
  526. else {
  527. int st = i - 1;
  528. while (i < limit) {
  529. c = s.charAt(i);
  530. if (!('A' <= c && c <= 'Z' || 'a' <= c && c <= 'z'))
  531. break;
  532. i++;
  533. }
  534. if (i <= st + 1)
  535. break syntax;
  536. int k;
  537. for (k = wtb.length; --k >= 0;)
  538. if (wtb[k].regionMatches(true, 0, s, st, i - st)) {
  539. int action = ttb[k];
  540. if (action != 0) {
  541. if (action == 1) { // pm
  542. if (hour > 12 || hour < 1)
  543. break syntax;
  544. else if (hour < 12)
  545. hour += 12;
  546. } else if (action == 14) { // am
  547. if (hour > 12 || hour < 1)
  548. break syntax;
  549. else if (hour == 12)
  550. hour = 0;
  551. } else if (action <= 13) { // month!
  552. if (mon < 0)
  553. mon = (byte) (action - 2);
  554. else
  555. break syntax;
  556. } else {
  557. tzoffset = action - 10000;
  558. }
  559. }
  560. break;
  561. }
  562. if (k < 0)
  563. break syntax;
  564. prevc = 0;
  565. }
  566. }
  567. if (year == Integer.MIN_VALUE || mon < 0 || mday < 0)
  568. break syntax;
  569. // Parse 2-digit years within the correct default century.
  570. if (year < 100) {
  571. synchronized (Date.class) {
  572. if (defaultCenturyStart == 0) {
  573. defaultCenturyStart = gcal.getCalendarDate().getYear() - 80;
  574. }
  575. }
  576. year += (defaultCenturyStart / 100) * 100;
  577. if (year < defaultCenturyStart) year += 100;
  578. }
  579. if (sec < 0)
  580. sec = 0;
  581. if (min < 0)
  582. min = 0;
  583. if (hour < 0)
  584. hour = 0;
  585. BaseCalendar cal = getCalendarSystem(year);
  586. if (tzoffset == -1) { // no time zone specified, have to use local
  587. BaseCalendar.Date ldate = (BaseCalendar.Date) cal.newCalendarDate(TimeZone.getDefaultRef());
  588. ldate.setDate(year, mon + 1, mday);
  589. ldate.setTimeOfDay(hour, min, sec, 0);
  590. return cal.getTime(ldate);
  591. }
  592. BaseCalendar.Date udate = (BaseCalendar.Date) cal.newCalendarDate(null); // no time zone
  593. udate.setDate(year, mon + 1, mday);
  594. udate.setTimeOfDay(hour, min, sec, 0);
  595. return cal.getTime(udate) + tzoffset * (60 * 1000);
  596. }
  597. // syntax error
  598. throw new IllegalArgumentException();
  599. }
  600. private final static String wtb[] = {
  601. "am", "pm",
  602. "monday", "tuesday", "wednesday", "thursday", "friday",
  603. "saturday", "sunday",
  604. "january", "february", "march", "april", "may", "june",
  605. "july", "august", "september", "october", "november", "december",
  606. "gmt", "ut", "utc", "est", "edt", "cst", "cdt",
  607. "mst", "mdt", "pst", "pdt"
  608. };
  609. private final static int ttb[] = {
  610. 14, 1, 0, 0, 0, 0, 0, 0, 0,
  611. 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
  612. 10000 + 0, 10000 + 0, 10000 + 0, // GMT/UT/UTC
  613. 10000 + 5 * 60, 10000 + 4 * 60, // EST/EDT
  614. 10000 + 6 * 60, 10000 + 5 * 60, // CST/CDT
  615. 10000 + 7 * 60, 10000 + 6 * 60, // MST/MDT
  616. 10000 + 8 * 60, 10000 + 7 * 60 // PST/PDT
  617. };
  618. /**
  619. * Returns a value that is the result of subtracting 1900 from the
  620. * year that contains or begins with the instant in time represented
  621. * by this <code>Date</code> object, as interpreted in the local
  622. * time zone.
  623. *
  624. * @return the year represented by this date, minus 1900.
  625. * @see java.util.Calendar
  626. * @deprecated As of JDK version 1.1,
  627. * replaced by <code>Calendar.get(Calendar.YEAR) - 1900</code>.
  628. */
  629. @Deprecated
  630. public int getYear() {
  631. return normalize().getYear() - 1900;
  632. }
  633. /**
  634. * Sets the year of this <tt>Date</tt> object to be the specified
  635. * value plus 1900. This <code>Date</code> object is modified so
  636. * that it represents a point in time within the specified year,
  637. * with the month, date, hour, minute, and second the same as
  638. * before, as interpreted in the local time zone. (Of course, if
  639. * the date was February 29, for example, and the year is set to a
  640. * non-leap year, then the new date will be treated as if it were
  641. * on March 1.)
  642. *
  643. * @param year the year value.
  644. * @see java.util.Calendar
  645. * @deprecated As of JDK version 1.1,
  646. * replaced by <code>Calendar.set(Calendar.YEAR, year + 1900)</code>.
  647. */
  648. @Deprecated
  649. public void setYear(int year) {
  650. getCalendarDate().setNormalizedYear(year + 1900);
  651. }
  652. /**
  653. * Returns a number representing the month that contains or begins
  654. * with the instant in time represented by this <tt>Date</tt> object.
  655. * The value returned is between <code>0</code> and <code>11</code>,
  656. * with the value <code>0</code> representing January.
  657. *
  658. * @return the month represented by this date.
  659. * @see java.util.Calendar
  660. * @deprecated As of JDK version 1.1,
  661. * replaced by <code>Calendar.get(Calendar.MONTH)</code>.
  662. */
  663. @Deprecated
  664. public int getMonth() {
  665. return normalize().getMonth() - 1; // adjust 1-based to 0-based
  666. }
  667. /**
  668. * Sets the month of this date to the specified value. This
  669. * <tt>Date</tt> object is modified so that it represents a point
  670. * in time within the specified month, with the year, date, hour,
  671. * minute, and second the same as before, as interpreted in the
  672. * local time zone. If the date was October 31, for example, and
  673. * the month is set to June, then the new date will be treated as
  674. * if it were on July 1, because June has only 30 days.
  675. *
  676. * @param month the month value between 0-11.
  677. * @see java.util.Calendar
  678. * @deprecated As of JDK version 1.1,
  679. * replaced by <code>Calendar.set(Calendar.MONTH, int month)</code>.
  680. */
  681. @Deprecated
  682. public void setMonth(int month) {
  683. int y = 0;
  684. if (month >= 12) {
  685. y = month / 12;
  686. month %= 12;
  687. } else if (month < 0) {
  688. y = CalendarUtils.floorDivide(month, 12);
  689. month = CalendarUtils.mod(month, 12);
  690. }
  691. BaseCalendar.Date d = getCalendarDate();
  692. if (y != 0) {
  693. d.setNormalizedYear(d.getNormalizedYear() + y);
  694. }
  695. d.setMonth(month + 1); // adjust 0-based to 1-based month numbering
  696. }
  697. /**
  698. * Returns the day of the month represented by this <tt>Date</tt> object.
  699. * The value returned is between <code>1</code> and <code>31</code>
  700. * representing the day of the month that contains or begins with the
  701. * instant in time represented by this <tt>Date</tt> object, as
  702. * interpreted in the local time zone.
  703. *
  704. * @return the day of the month represented by this date.
  705. * @see java.util.Calendar
  706. * @deprecated As of JDK version 1.1,
  707. * replaced by <code>Calendar.get(Calendar.DAY_OF_MONTH)</code>.
  708. * @deprecated
  709. */
  710. @Deprecated
  711. public int getDate() {
  712. return normalize().getDayOfMonth();
  713. }
  714. /**
  715. * Sets the day of the month of this <tt>Date</tt> object to the
  716. * specified value. This <tt>Date</tt> object is modified so that
  717. * it represents a point in time within the specified day of the
  718. * month, with the year, month, hour, minute, and second the same
  719. * as before, as interpreted in the local time zone. If the date
  720. * was April 30, for example, and the date is set to 31, then it
  721. * will be treated as if it were on May 1, because April has only
  722. * 30 days.
  723. *
  724. * @param date the day of the month value between 1-31.
  725. * @see java.util.Calendar
  726. * @deprecated As of JDK version 1.1,
  727. * replaced by <code>Calendar.set(Calendar.DAY_OF_MONTH, int date)</code>.
  728. */
  729. @Deprecated
  730. public void setDate(int date) {
  731. getCalendarDate().setDayOfMonth(date);
  732. }
  733. /**
  734. * Returns the day of the week represented by this date. The
  735. * returned value (<tt>0</tt> = Sunday, <tt>1</tt> = Monday,
  736. * <tt>2</tt> = Tuesday, <tt>3</tt> = Wednesday, <tt>4</tt> =
  737. * Thursday, <tt>5</tt> = Friday, <tt>6</tt> = Saturday)
  738. * represents the day of the week that contains or begins with
  739. * the instant in time represented by this <tt>Date</tt> object,
  740. * as interpreted in the local time zone.
  741. *
  742. * @return the day of the week represented by this date.
  743. * @see java.util.Calendar
  744. * @deprecated As of JDK version 1.1,
  745. * replaced by <code>Calendar.get(Calendar.DAY_OF_WEEK)</code>.
  746. */
  747. @Deprecated
  748. public int getDay() {
  749. return normalize().getDayOfWeek() - gcal.SUNDAY;
  750. }
  751. /**
  752. * Returns the hour represented by this <tt>Date</tt> object. The
  753. * returned value is a number (<tt>0</tt> through <tt>23</tt>)
  754. * representing the hour within the day that contains or begins
  755. * with the instant in time represented by this <tt>Date</tt>
  756. * object, as interpreted in the local time zone.
  757. *
  758. * @return the hour represented by this date.
  759. * @see java.util.Calendar
  760. * @deprecated As of JDK version 1.1,
  761. * replaced by <code>Calendar.get(Calendar.HOUR_OF_DAY)</code>.
  762. */
  763. @Deprecated
  764. public int getHours() {
  765. return normalize().getHours();
  766. }
  767. /**
  768. * Sets the hour of this <tt>Date</tt> object to the specified value.
  769. * This <tt>Date</tt> object is modified so that it represents a point
  770. * in time within the specified hour of the day, with the year, month,
  771. * date, minute, and second the same as before, as interpreted in the
  772. * local time zone.
  773. *
  774. * @param hours the hour value.
  775. * @see java.util.Calendar
  776. * @deprecated As of JDK version 1.1,
  777. * replaced by <code>Calendar.set(Calendar.HOUR_OF_DAY, int hours)</code>.
  778. */
  779. @Deprecated
  780. public void setHours(int hours) {
  781. getCalendarDate().setHours(hours);
  782. }
  783. /**
  784. * Returns the number of minutes past the hour represented by this date,
  785. * as interpreted in the local time zone.
  786. * The value returned is between <code>0</code> and <code>59</code>.
  787. *
  788. * @return the number of minutes past the hour represented by this date.
  789. * @see java.util.Calendar
  790. * @deprecated As of JDK version 1.1,
  791. * replaced by <code>Calendar.get(Calendar.MINUTE)</code>.
  792. */
  793. @Deprecated
  794. public int getMinutes() {
  795. return normalize().getMinutes();
  796. }
  797. /**
  798. * Sets the minutes of this <tt>Date</tt> object to the specified value.
  799. * This <tt>Date</tt> object is modified so that it represents a point
  800. * in time within the specified minute of the hour, with the year, month,
  801. * date, hour, and second the same as before, as interpreted in the
  802. * local time zone.
  803. *
  804. * @param minutes the value of the minutes.
  805. * @see java.util.Calendar
  806. * @deprecated As of JDK version 1.1,
  807. * replaced by <code>Calendar.set(Calendar.MINUTE, int minutes)</code>.
  808. */
  809. @Deprecated
  810. public void setMinutes(int minutes) {
  811. getCalendarDate().setMinutes(minutes);
  812. }
  813. /**
  814. * Returns the number of seconds past the minute represented by this date.
  815. * The value returned is between <code>0</code> and <code>61</code>. The
  816. * values <code>60</code> and <code>61</code> can only occur on those
  817. * Java Virtual Machines that take leap seconds into account.
  818. *
  819. * @return the number of seconds past the minute represented by this date.
  820. * @see java.util.Calendar
  821. * @deprecated As of JDK version 1.1,
  822. * replaced by <code>Calendar.get(Calendar.SECOND)</code>.
  823. */
  824. @Deprecated
  825. public int getSeconds() {
  826. return normalize().getSeconds();
  827. }
  828. /**
  829. * Sets the seconds of this <tt>Date</tt> to the specified value.
  830. * This <tt>Date</tt> object is modified so that it represents a
  831. * point in time within the specified second of the minute, with
  832. * the year, month, date, hour, and minute the same as before, as
  833. * interpreted in the local time zone.
  834. *
  835. * @param seconds the seconds value.
  836. * @see java.util.Calendar
  837. * @deprecated As of JDK version 1.1,
  838. * replaced by <code>Calendar.set(Calendar.SECOND, int seconds)</code>.
  839. */
  840. @Deprecated
  841. public void setSeconds(int seconds) {
  842. getCalendarDate().setSeconds(seconds);
  843. }
  844. /**
  845. * Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT
  846. * represented by this <tt>Date</tt> object.
  847. *
  848. * @return the number of milliseconds since January 1, 1970, 00:00:00 GMT
  849. * represented by this date.
  850. */
  851. public long getTime() {
  852. return getTimeImpl();
  853. }
  854. private final long getTimeImpl() {
  855. if (cdate != null && !cdate.isNormalized()) {
  856. normalize();
  857. }
  858. return fastTime;
  859. }
  860. /**
  861. * Sets this <code>Date</code> object to represent a point in time that is
  862. * <code>time</code> milliseconds after January 1, 1970 00:00:00 GMT.
  863. *
  864. * @param time the number of milliseconds.
  865. */
  866. public void setTime(long time) {
  867. fastTime = time;
  868. cdate = null;
  869. }
  870. /**
  871. * Tests if this date is before the specified date.
  872. *
  873. * @param when a date.
  874. * @return <code>true</code> if and only if the instant of time
  875. * represented by this <tt>Date</tt> object is strictly
  876. * earlier than the instant represented by <tt>when</tt>;
  877. * <code>false</code> otherwise.
  878. * @exception NullPointerException if <code>when</code> is null.
  879. */
  880. public boolean before(Date when) {
  881. return getMillisOf(this) < getMillisOf(when);
  882. }
  883. /**
  884. * Tests if this date is after the specified date.
  885. *
  886. * @param when a date.
  887. * @return <code>true</code> if and only if the instant represented
  888. * by this <tt>Date</tt> object is strictly later than the
  889. * instant represented by <tt>when</tt>;
  890. * <code>false</code> otherwise.
  891. * @exception NullPointerException if <code>when</code> is null.
  892. */
  893. public boolean after(Date when) {
  894. return getMillisOf(this) > getMillisOf(when);
  895. }
  896. /**
  897. * Compares two dates for equality.
  898. * The result is <code>true</code> if and only if the argument is
  899. * not <code>null</code> and is a <code>Date</code> object that
  900. * represents the same point in time, to the millisecond, as this object.
  901. * <p>
  902. * Thus, two <code>Date</code> objects are equal if and only if the
  903. * <code>getTime</code> method returns the same <code>long</code>
  904. * value for both.
  905. *
  906. * @param obj the object to compare with.
  907. * @return <code>true</code> if the objects are the same;
  908. * <code>false</code> otherwise.
  909. * @see java.util.Date#getTime()
  910. */
  911. public boolean equals(Object obj) {
  912. return obj instanceof Date && getTime() == ((Date) obj).getTime();
  913. }
  914. /**
  915. * Returns the millisecond value of this <code>Date</code> object
  916. * without affecting its internal state.
  917. */
  918. static final long getMillisOf(Date date) {
  919. if (date.cdate == null || date.cdate.isNormalized()) {
  920. return date.fastTime;
  921. }
  922. BaseCalendar.Date d = (BaseCalendar.Date) date.cdate.clone();
  923. return gcal.getTime(d);
  924. }
  925. /**
  926. * Compares two Dates for ordering.
  927. *
  928. * @param anotherDate the <code>Date</code> to be compared.
  929. * @return the value <code>0</code> if the argument Date is equal to
  930. * this Date; a value less than <code>0</code> if this Date
  931. * is before the Date argument; and a value greater than
  932. * <code>0</code> if this Date is after the Date argument.
  933. * @since 1.2
  934. * @exception NullPointerException if <code>anotherDate</code> is null.
  935. */
  936. public int compareTo(Date anotherDate) {
  937. long thisTime = getMillisOf(this);
  938. long anotherTime = getMillisOf(anotherDate);
  939. return (thisTime<anotherTime ? -1 : (thisTime==anotherTime ? 0 : 1));
  940. }
  941. /**
  942. * Returns a hash code value for this object. The result is the
  943. * exclusive OR of the two halves of the primitive <tt>long</tt>
  944. * value returned by the {@link Date#getTime}
  945. * method. That is, the hash code is the value of the expression:
  946. * <blockquote><pre>
  947. * (int)(this.getTime()^(this.getTime() >>> 32))</pre></blockquote>
  948. *
  949. * @return a hash code value for this object.
  950. */
  951. public int hashCode() {
  952. long ht = this.getTime();
  953. return (int) ht ^ (int) (ht >> 32);
  954. }
  955. /**
  956. * Converts this <code>Date</code> object to a <code>String</code>
  957. * of the form:
  958. * <blockquote><pre>
  959. * dow mon dd hh:mm:ss zzz yyyy</pre></blockquote>
  960. * where:<ul>
  961. * <li><tt>dow</tt> is the day of the week (<tt>Sun, Mon, Tue, Wed,
  962. * Thu, Fri, Sat</tt>).
  963. * <li><tt>mon</tt> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun,
  964. * Jul, Aug, Sep, Oct, Nov, Dec</tt>).
  965. * <li><tt>dd</tt> is the day of the month (<tt>01</tt> through
  966. * <tt>31</tt>), as two decimal digits.
  967. * <li><tt>hh</tt> is the hour of the day (<tt>00</tt> through
  968. * <tt>23</tt>), as two decimal digits.
  969. * <li><tt>mm</tt> is the minute within the hour (<tt>00</tt> through
  970. * <tt>59</tt>), as two decimal digits.
  971. * <li><tt>ss</tt> is the second within the minute (<tt>00</tt> through
  972. * <tt>61</tt>, as two decimal digits.
  973. * <li><tt>zzz</tt> is the time zone (and may reflect daylight saving
  974. * time). Standard time zone abbreviations include those
  975. * recognized by the method <tt>parse</tt>. If time zone
  976. * information is not available, then <tt>zzz</tt> is empty -
  977. * that is, it consists of no characters at all.
  978. * <li><tt>yyyy</tt> is the year, as four decimal digits.
  979. * </ul>
  980. *
  981. * @return a string representation of this date.
  982. * @see java.util.Date#toLocaleString()
  983. * @see java.util.Date#toGMTString()
  984. */
  985. public String toString() {
  986. // "EEE MMM dd HH:mm:ss zzz yyyy";
  987. BaseCalendar.Date date = normalize();
  988. StringBuilder sb = new StringBuilder(28);
  989. int index = date.getDayOfWeek();
  990. if (index == gcal.SUNDAY) {
  991. index = 8;
  992. }
  993. convertToAbbr(sb, wtb[index]).append(' '); // EEE
  994. convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' '); // MMM
  995. CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 2).append(' '); // dd
  996. CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':'); // HH
  997. CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm
  998. CalendarUtils.sprintf0d(sb, date.getSeconds(), 2).append(' '); // ss
  999. TimeZone zi = date.getZone();
  1000. if (zi != null) {
  1001. sb.append(zi.getDisplayName(date.isDaylightTime(), zi.SHORT, Locale.US)); // zzz
  1002. } else {
  1003. sb.append("GMT");
  1004. }
  1005. sb.append(' ').append(date.getYear()); // yyyy
  1006. return sb.toString();
  1007. }
  1008. /**
  1009. * Converts the given name to its 3-letter abbreviation (e.g.,
  1010. * "monday" -> "Mon") and stored the abbreviation in the given
  1011. * <code>StringBuilder</code>.
  1012. */
  1013. private static final StringBuilder convertToAbbr(StringBuilder sb, String name) {
  1014. sb.append(Character.toUpperCase(name.charAt(0)));
  1015. sb.append(name.charAt(1)).append(name.charAt(2));
  1016. return sb;
  1017. }
  1018. /**
  1019. * Creates a string representation of this <tt>Date</tt> object in an
  1020. * implementation-dependent form. The intent is that the form should
  1021. * be familiar to the user of the Java application, wherever it may
  1022. * happen to be running. The intent is comparable to that of the
  1023. * "<code>%c</code>" format supported by the <code>strftime()</code>
  1024. * function of ISO&nbsp;C.
  1025. *
  1026. * @return a string representation of this date, using the locale
  1027. * conventions.
  1028. * @see java.text.DateFormat
  1029. * @see java.util.Date#toString()
  1030. * @see java.util.Date#toGMTString()
  1031. * @deprecated As of JDK version 1.1,
  1032. * replaced by <code>DateFormat.format(Date date)</code>.
  1033. */
  1034. @Deprecated
  1035. public String toLocaleString() {
  1036. DateFormat formatter = DateFormat.getDateTimeInstance();
  1037. return formatter.format(this);
  1038. }
  1039. /**
  1040. * Creates a string representation of this <tt>Date</tt> object of
  1041. * the form:
  1042. * <blockquote<pre>
  1043. * d mon yyyy hh:mm:ss GMT</pre></blockquote>
  1044. * where:<ul>
  1045. * <li><i>d</i> is the day of the month (<tt>1</tt> through <tt>31</tt>),
  1046. * as one or two decimal digits.
  1047. * <li><i>mon</i> is the month (<tt>Jan, Feb, Mar, Apr, May, Jun, Jul,
  1048. * Aug, Sep, Oct, Nov, Dec</tt>).
  1049. * <li><i>yyyy</i> is the year, as four decimal digits.
  1050. * <li><i>hh</i> is the hour of the day (<tt>00</tt> through <tt>23</tt>),
  1051. * as two decimal digits.
  1052. * <li><i>mm</i> is the minute within the hour (<tt>00</tt> through
  1053. * <tt>59</tt>), as two decimal digits.
  1054. * <li><i>ss</i> is the second within the minute (<tt>00</tt> through
  1055. * <tt>61</tt>), as two decimal digits.
  1056. * <li><i>GMT</i> is exactly the ASCII letters "<tt>GMT</tt>" to indicate
  1057. * Greenwich Mean Time.
  1058. * </ul><p>
  1059. * The result does not depend on the local time zone.
  1060. *
  1061. * @return a string representation of this date, using the Internet GMT
  1062. * conventions.
  1063. * @see java.text.DateFormat
  1064. * @see java.util.Date#toString()
  1065. * @see java.util.Date#toLocaleString()
  1066. * @deprecated As of JDK version 1.1,
  1067. * replaced by <code>DateFormat.format(Date date)</code>, using a
  1068. * GMT <code>TimeZone</code>.
  1069. */
  1070. @Deprecated
  1071. public String toGMTString() {
  1072. // d MMM yyyy HH:mm:ss 'GMT'
  1073. long t = getTime();
  1074. BaseCalendar cal = getCalendarSystem(t);
  1075. BaseCalendar.Date date =
  1076. (BaseCalendar.Date) cal.getCalendarDate(getTime(), (TimeZone)null);
  1077. StringBuilder sb = new StringBuilder(32);
  1078. CalendarUtils.sprintf0d(sb, date.getDayOfMonth(), 1).append(' '); // d
  1079. convertToAbbr(sb, wtb[date.getMonth() - 1 + 2 + 7]).append(' '); // MMM
  1080. sb.append(date.getYear()).append(' '); // yyyy
  1081. CalendarUtils.sprintf0d(sb, date.getHours(), 2).append(':'); // HH
  1082. CalendarUtils.sprintf0d(sb, date.getMinutes(), 2).append(':'); // mm
  1083. CalendarUtils.sprintf0d(sb, date.getSeconds(), 2); // ss
  1084. sb.append(" GMT"); // ' GMT'
  1085. return sb.toString();
  1086. }
  1087. /**
  1088. * Returns the offset, measured in minutes, for the local time zone
  1089. * relative to UTC that is appropriate for the time represented by
  1090. * this <code>Date</code> object.
  1091. * <p>
  1092. * For example, in Massachusetts, five time zones west of Greenwich:
  1093. * <blockquote><pre>
  1094. * new Date(96, 1, 14).getTimezoneOffset() returns 300</pre></blockquote>
  1095. * because on February 14, 1996, standard time (Eastern Standard Time)
  1096. * is in use, which is offset five hours from UTC; but:
  1097. * <blockquote><pre>
  1098. * new Date(96, 5, 1).getTimezoneOffset() returns 240</pre></blockquote>
  1099. * because on June 1, 1996, daylight saving time (Eastern Daylight Time)
  1100. * is in use, which is offset only four hours from UTC.<p>
  1101. * This method produces the same result as if it computed:
  1102. * <blockquote><pre>
  1103. * (this.getTime() - UTC(this.getYear(),
  1104. * this.getMonth(),
  1105. * this.getDate(),
  1106. * this.getHours(),
  1107. * this.getMinutes(),
  1108. * this.getSeconds())) / (60 * …

Large files files are truncated, but you can click here to view the full file