📄 javautil.doc2.html
字号:
<a name="20796"></a>
This <code>Date</code> object is modified so that it represents a point in time that is <code>time</code> milliseconds
after the epoch (00:00:00 GMT on January 1, 1970).
<p><a name="7490"></a>
<p><font size=+1><strong>21.3.25 </strong> <code>public boolean <code><b>before</b></code>(Date when)</code></font>
<p>
<a name="20806"></a>
The result is <code>true</code> if and only if the instant represented by this <code>Date</code> object is
strictly earlier than the instant represented by <code>when</code>.
<p><a name="7491"></a>
<p><font size=+1><strong>21.3.26 </strong> <code>public boolean <code><b>after</b></code>(Date when)</code></font>
<p>
<a name="20808"></a>
The result is <code>true</code> if and only if the instant represented by this <code>Date</code> object is
strictly later than the instant represented by <code>when</code>.
<p><a name="7495"></a>
<p><font size=+1><strong>21.3.27 </strong> <code>public String <code><b>toLocaleString</b></code>()</code></font>
<p>
<a name="20815"></a>
This <code>Date</code> object is converted to a <code>String</code> of an implementation-dependent form.
The general intent is that the form should be familiar to the user of the Java application,
wherever it may happen to be running. The intent is comparable to that of
the <code>%c</code> format supported by the <code>strftime</code> function of ISO C.
<p><a name="20840"></a>
See also methods <code>toString</code> <a href="javautil.doc2.html#8902">(§21.3.7)</a> and <code>toGMTString</code> <a href="javautil.doc2.html#7496">(§21.3.28)</a>.<p>
<a name="7496"></a>
<p><font size=+1><strong>21.3.28 </strong> <code>public String <code><b>toGMTString</b></code>()</code></font>
<p>
<a name="20852"></a>
This <code>Date</code> object is converted to a <code>String</code> of length 23 or 24 of the form:
<p><pre><a name="20853"></a>"<i>d</i> <i>mon</i> <i>yyyy</i> <i>hh</i>:<i>mm</i>:<i>ss</i> <i>GMT</i>"
</pre><a name="20854"></a>
where:<p>
<ul><a name="23618"></a>
<li><i>d</i> is the day of the month (<code>1</code> through <code>31</code>), as one or two decimal digits.
<a name="23619"></a>
<li><i>mon</i> is the month (<code>Jan</code>, <code>Feb</code>, <code>Mar</code>, <code>Apr</code>, <code>May</code>, <code>Jun</code>, <code>Jul</code>, <code>Aug</code>, <code>Sep</code>, <code>Oct</code>, <code>Nov</code>, <code>Dec</code>).
<a name="23620"></a>
<li><i>yyyy</i> is the year, as four decimal digits.
<a name="23621"></a>
<li><i>hh</i> is the hour of the day (<code>00</code> through <code>23</code>), as two decimal digits.
<a name="20859"></a>
<li><i>mm</i> is the minute within the hour (<code>00</code> through <code>59</code>), as two decimal digits.
<a name="20860"></a>
<li><i>ss</i> is the second within the minute (<code>00</code> through <code>61</code>), as two decimal digits.
<a name="20861"></a>
<li><i>GMT</i> is exactly the ASCII letters "<code>GMT</code>" to indicate Greenwich Mean Time.
</ul><a name="20830"></a>
The result does not depend on the local time zone.<p>
<a name="20987"></a>
See also methods <code>toString</code> <a href="javautil.doc2.html#8902">(§21.3.7)</a> and <code>toLocaleString</code> <a href="javautil.doc2.html#7495">(§21.3.27)</a>.<p>
<a name="7497"></a>
<p><font size=+1><strong>21.3.29 </strong> <code>public int <code><b>getTimezoneOffset</b></code>()</code></font>
<p>
<a name="20988"></a>
This method returns the offset, measured in minutes, for the local time zone relative
to UTC that is appropriate for the time represented by this <code>Date</code> object.
<p><a name="20989"></a>
For example, in Massachusetts, five time zones west of Greenwich:<p>
<pre><a name="20990"></a>new Date(96, 1, 14).getTimezoneOffset() returns 300
</pre><a name="20995"></a>
because on February 14, 1996, standard time (Eastern Standard Time) is in use, which is offset five hours from UTC; but:<p>
<pre><a name="20998"></a>new Date(96, 5, 1).getTimezoneOffset() returns 240
</pre><a name="20999"></a>
because on May 1, 1996, daylight saving time (Eastern Daylight Time) is in use, which is offset only four hours from UTC.<p>
<a name="21070"></a>
This method produces the same result as if it computed:<p>
<pre><a name="21071"></a>
(this.getTime() - UTC(this.getYear(),
<a name="21072"></a> this.getMonth(),
<a name="21058"></a> this.getDate(),
<a name="21066"></a> this.getHours(),
<a name="21063"></a> this.getMinutes(),
<a name="21067"></a> this.getSeconds())) / (60 * 1000)
</pre><a name="20922"></a>
<p><font size=+1><strong>21.3.30 </strong> <code>public static long <code><b>UTC</b></code>(int year, int month, int date,<br>      int hours, int minutes, int seconds)</code></font>
<p>
<a name="21083"></a>
The arguments are interpreted as a year, month, day of the month, hour of the day,
minute within the hour, and second within the minute, exactly as for the <code>Date</code> constructor
of six arguments <a href="javautil.doc2.html#7471">(§21.3.5)</a>, except that the arguments are interpreted relative
to UTC rather than to the local time zone. The time indicated is returned
represented as the distance, measured in milliseconds, of that time from the epoch
(00:00:00 GMT on January 1, 1970).
<p><a name="21075"></a>
<p><font size=+1><strong>21.3.31 </strong> <code>public static long <code><b>parse</b></code>(String s)<br>throws IllegalArgumentException</code></font>
<p>
<a name="21097"></a>
An attempt is made to interpret the string <code>s</code> as a representation of a date and time.
If the attempt is successful, the time indicated is returned represented as the distance,
measured in milliseconds, of that time from the epoch (00:00:00 GMT on
January 1, 1970). If the attempt fails, an <code>IllegalArgumentException</code> is thrown.
<p><a name="21133"></a>
The string <code>s</code> is processed from left to right, looking for data of interest.<p>
<a name="21109"></a>
Any material in <code>s</code> that is within the ASCII parenthesis characters <code>(</code> and <code>)</code> is ignored. Parentheses may be nested. Otherwise, the only characters permitted within <code>s</code> are these ASCII characters:<p>
<pre><a name="21113"></a>
abcdefghijklmnopqrstuvwxyz
<a name="21117"></a>ABCDEFGHIJKLMNOPQRSTUVWXYZ
<a name="21120"></a>0123456789,+-:/
</pre><a name="21121"></a>
and whitespace characters <a href="javalang.doc10.html#36320">(§20.5.19)</a>.<p>
<a name="21127"></a>
A consecutive sequence of decimal digits is treated as a decimal number:<p>
<ul><a name="21128"></a>
<li>If a number is preceded by <code>+</code> or <code>-</code> and a year has already been recognized, then the number is a time-zone offset. If the number is less than 24, it is an offset measured in hours. Otherwise, it is regarded as an offset in minutes, expressed in 24-hour time format without punctuation. A preceding <code>+</code> means an eastward offset and a preceding <code>-</code> means a westward offset. Time zone offsets are always relative to UTC (Greenwich). Thus, for example, <code>-5</code> occurring in the string would mean "five hours west of Greenwich" and <code>+0430</code> would mean "four hours and thirty minutes east of Greenwich." It is permitted for the string to specify <code>GMT</code>, <code>UT</code>, or <code>UTC</code> redundantly-for example, <code>GMT-5</code> or <code>utc+0430</code>.
<a name="21146"></a>
<li>If a number is greater than 70, it is regarded as a year number. It must be followed by a space, comma, slash, or end of string. If it is greater than 1900, then 1900 is subtracted from it.
<a name="21150"></a>
<li>If the number is followed by a colon, it is regarded as an hour, unless an hour has already been recognized, in which case it is regarded as a minute.
<a name="21153"></a>
<li>If the number is followed by a slash, it is regarded as a month (it is decreased by <code>1</code> to produce a number in the range <code>0</code> to <code>11</code>), unless a month has already been recognized, in which case it is regarded as a day of the month.
<a name="21165"></a>
<li>If the number is followed by whitespace, a comma, a hyphen, or end of string, then if an hour has been recognized but not a minute, it is regarded as a minute; otherwise, if a minute has been recognized but not a second, it is regarded as a second; otherwise, it is regarded as a day of the month.
</ul><a name="23635"></a>
A consecutive sequence of letters is regarded as a word and treated as follows:<p>
<ul><a name="23636"></a>
<li>A word that matches <code>AM</code>, ignoring case, is ignored (but the parse fails if an hour has not been recognized or is less than <code>1</code> or greater than <code>12</code>).
<a name="21181"></a>
<li>A word that matches <code>PM</code>, ignoring case, adds <code>12</code> to the hour (but the parse fails if an hour has not been recognized or is less than <code>1</code> or greater than <code>12</code>).
<a name="21182"></a>
<li>Any word that matches any prefix of <code>SUNDAY</code>, <code>MONDAY</code>, <code>TUESDAY</code>, <code>WEDNESDAY</code>, <code>THURSDAY</code>, <code>FRIDAY</code>, or <code>SATURDAY</code>, ignoring case, is ignored. For example, <code>sat</code>, <code>Friday</code>, <code>TUE</code>, and <code>Thurs</code> are ignored.
<a name="21189"></a>
<li>Otherwise, any word that matches any prefix of <code>JANUARY</code>, <code>FEBRUARY</code>, <code>MARCH</code>, <code>APRIL</code>, <code>MAY</code>, <code>JUNE</code>, <code>JULY</code>, <code>AUGUST</code>, <code>SEPTEMBER</code>, <code>OCTOBER</code>, <code>NOVEMBER</code>, or <code>DECEMBER</code>,  ignoring case, and considering them in the order given here, is recognized  as specifying a month and is converted to a number (<code>0</code> to <code>11</code>). For example, <code>aug</code>, <code>Sept</code>, <code>april</code>, and <code>NOV</code> are recognized as months. So is <code>Ma</code>, which is recognized as <code>MARCH</code>, not <code>MAY</code>.
<a name="21192"></a>
<li>Any word that matches <code>GMT</code>, <code>UT</code>, or <code>UTC</code>, ignoring case, is treated as referring to UTC.
<a name="21195"></a>
<li>Any word that matches <code>EST</code>, <code>CST</code>, <code>MST</code>, or <code>PST</code>, ignoring case, is recognized as referring to the time zone in North America that is five, six, seven, or eight hours west of Greenwich, respectively. Any word that matches <code>EDT</code>, <code>CDT</code>, <code>MDT</code>, or <code>PDT</code>, ignoring case, is recognized as referring to the same time zone, respectively, during daylight saving time. (In the future, this method may be upgraded to recognize other time zone designations.)
</ul><a name="21210"></a>
Once the entire string <code>s</code> has been scanned, it is converted to a time result in one of two ways. If a time zone or time-zone offset has been recognized, then the year, month, day of month, hour, minute, and second are interpreted in UTC <a href="javautil.doc2.html#20922">(§21.3.30)</a> and then the time-zone offset is applied. Otherwise, the year, month, day of month, hour, minute, and second are interpreted in the local time zone.<p>
<hr>
<!-- This inserts footnotes--><p>
<a href="index.html">Contents</a> | <a href="javautil.doc1.html">Prev</a> | <a href="javautil.doc3.html">Next</a> | <a href="j.index.doc1.html">Index</a>
<p>
<font size=-1>Java Language Specification (HTML generated by Suzette Pelouch on February 24, 1998)<br>
<i><a href="jcopyright.doc.html">Copyright © 1996 Sun Microsystems, Inc.</a>
All rights reserved</i>
<br>
Please send any comments or corrections to <a href="mailto:doug.kramer@sun.com">doug.kramer@sun.com</a>
</font>
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -