On this page
  1. Date (legacy)
  2. Import
  3. Signature & Overview
  4. Notes & Pitfalls
  5. Example

Date (legacy)

Prev: `Duration` | Up: java.time | Next: java.nio.file
Rel: java.time.Instant, java.time, java/builtins
Ref: Java Docs — Date (legacy)
Tags: #public #prog #java #stdlib #java_time #tier/legacy


Import

import java.time.*;

Signature & Overview

java.util.Date  /* + Calendar, SimpleDateFormat */

Mutable, 0-indexed-month, non-thread-safe Java 1.0 date API.

Legacy / Avoid: Prefer java.time.Instant in all modern Java.

Notes & Pitfalls

Example

import java.time.Instant;
import java.util.Date;

Instant now = Instant.now();
Date legacy = Date.from(now);
assert legacy.toInstant().equals(now.truncatedTo(java.time.temporal.ChronoUnit.MILLIS));

Linked from

Related notes