Home

javautilDate

java.util.Date is a class in the Java standard library that represents a specific instant in time, with millisecond precision. It stores the time as the number of milliseconds elapsed since the epoch, 1970-01-01T00:00:00Z. The value can be retrieved with getTime() and modified with setTime(long). The toString() method formats the date using the system's default time zone and locale.

Constructors for java.util.Date include Date() for the current time and Date(long date) for a date given as

java.util.Date implements Serializable and is comparable to other Date instances. It provides methods such as after(Date

Limitations and deprecation: Many methods that access calendar fields directly, such as getYear(), getMonth(), getDate(), getHours(),

Modern usage: In contemporary code, java.time.Instant is preferred for timestamps, with conversions to and from Date

See also: java.util.Calendar, java.time package.

milliseconds
since
the
epoch.
Other
constructors
that
existed
in
early
Java
versions
(for
example,
using
year,
month,
and
day)
are
deprecated.
The
class
is
mutable,
allowing
changes
to
the
stored
instant
after
creation.
when),
before(Date
when),
equals(Object
obj),
hashCode(),
and
compareTo(Date
anotherDate).
It
also
offers
toInstant()
to
convert
the
value
to
a
java.time.Instant
in
modern
Java.
getMinutes(),
and
getSeconds(),
are
deprecated
in
favor
of
more
robust
APIs.
For
date
arithmetic
and
component
extraction,
developers
typically
use
java.util.Calendar
or
the
newer
java.time
package
introduced
in
Java
8.
as
needed
(Date.from(Instant)
and
Date.toInstant()).
For
formatting,
parsing,
and
complex
date-time
calculations,
java.time
classes
like
LocalDateTime,
ZonedDateTime,
and
DateTimeFormatter
are
recommended.