Java Reference
In-Depth Information
the Date object, respectively. It contains a
getDay()
method that returns the day of the
week (0 for Sunday and 6 for Saturday). There are corresponding setter methods such
as
setHours()
,
setDate()
, and so on to set the date and time components. There are
another set of getters and setters that work with UTC date and time; their names are
based on the pattern
getUTCXxx
and
setUTCXxx
such as
getUTCYear()
,
getUTCHours()
,
setUTCYears()
,
setUTCHours()
, and so on. The
getTime()
and
setTime()
methods work
with milliseconds elapsed since midnight January 1970. The
Date
object contains several
methods named such as
toXxxString()
to convert the date in a specific string format.
For example, the
toDateString()
returns a human-readable string format of the date
portion whereas
toTimeString()
works the same way but on the time portion.
The
Date.parse(str)
static method parses the specified
str
considering it as a
date and time in the
YYYY-MM-DDTHH:mm:ss.sssZ
format and returns the number of
milliseconds elapsed since midnight January 1, 1970 UTC and the parsed date and time.
The Math Object
The Math object contains properties that are mathematical constants and functions.
Table
4-14
lists the properties of the Math object with their descriptions. The properties of
the Math object are self-explanatory; I will not discuss any examples of using them.
Table 4-14.
The List of Properties and Methods of the Math Object
Property/Method
Description
Math.E
The Number value for e, the base of the natural logarithms, which
is approximately 2.7182818284590452354
Math.LN10
The Number value for the natural logarithm of 10, which is
approximately 2.302585092994046
Math.LN2
The Number value for the natural logarithm of 2, which is
approximately 0.6931471805599453
Math.LOG2E
The Number value for the base-2 logarithm of e, which is
approximately 1.4426950408889634
Math.LOG10E
The Number value for the base-10 logarithm of e which is
approximately 0.4342944819032518
Math.PI
The Number value for p, the ratio of the circumference of a circle
to its diameter, which is approximately 3.1415926535897932
Math.SQRT1_2
The Number value for the square root of 0.50 which is
approximately 0.7071067811865476
Math.SQRT2
The Number value for the square root of 2, which is approximately
1.4142135623730951
Math.abs(x)
Returns the absolute value of x. For example, both
Math.abs(2)
and
Math.abs(-2)
return 2
(
continued
)
Search WWH ::
Custom Search