🌐
GeeksforGeeks
geeksforgeeks.org › java › util-date-class-methods-java-examples
util.date class methods in Java with Examples - GeeksforGeeks
September 8, 2021 - Sets this Date object to represent a point in time that is time milliseconds after January 1, 1970 00:00:00 GMT. Syntax: public void setTime(long time) Parameters: time : the number of milliseconds. .hashCode() : java.util.Date.hashCode() method ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.date
Date Class (Java.Util) | Microsoft Learn
The class Date represents a specific instant in time, with millisecond precision. [Android.Runtime.Register("java/util/Date", DoNotGenerateAcw=true)] public class Date : Java.Lang.Object, IDisposable, Java.Interop.IJavaPeerable, Java.IO.ISerializable, Java.Lang.ICloneable, Java.Lang.IComparable
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › util › Date.html
Date (Java Platform SE 8 )
October 20, 2025 - Because of the manner in which ... to methods for these purposes need not fall within the indicated ranges; for example, a date may be specified as January 32 and is interpreted as meaning February 1....
🌐
Oracle
docs.oracle.com › javame › config › cldc › ref-impl › cldc1.0 › jsr030 › java › util › Date.html
java.util Class Date
java.lang.Object | +--java.util.Date · public class Date · extends Object · The class Date represents a specific instant in time, with millisecond precision. This Class has been subset for the MID Profile based on JDK 1.3. In the full API, the class Date had two additional functions.
🌐
Java Code Geeks
examples.javacodegeeks.com › home › java development › core java › util › date
java.util.Date Example – How to use Java util date
November 9, 2020 - Today's date is: Thu Jan 02 16:00:56 EET 2014 Today's date is: 02/01/2014 04:00:56 Tue Apr 02 11:35:42 EEST 2013 Date1 is: 17/07/1989 Date2 is: 15/10/2007 Date1 is earlier than Date2 Date1 is: 27/09/2012 Date2 is: 27/09/2009 Date1 is later than Date2 · This was an example of java.util.date.
🌐
TutorialsPoint
tutorialspoint.com › java › util › java_util_date.htm
Java Date Class
package com.tutorialspoint; import ... main(String[] args) { // create a date of current time Date date = Date.from(Instant.now()); // print the date instance System.out.println("Date: " + date.toString()); } }...
🌐
How to do in Java
howtodoinjava.com › home › java date time › guide to java.util.date class
Guide to java.util.Date Class - HowToDoInJava
February 17, 2022 - SimpleDateFormat sdf = new SimpleDateFormat("dd-M-yyyy hh:mm:ss"); String dateInString = "15-10-2015 10:20:56"; Date date = sdf.parse(dateInString); java.util.Date class represents the date and time elapsed since the epoch.
🌐
MIT
web.mit.edu › java_v1.0.2 › www › javadoc › java.util.Date.html
Class java.util.Date
java.lang.Object | +----java.util.Date · public class Date · extends Object A wrapper for a date. This class lets you manipulate dates in a system independent way.
🌐
CodeGym
codegym.cc › java blog › java classes › java.util.date class
Java.util.Date Class
February 14, 2025 - After that, we have used the date2.after(date1) and date2.before(date1) methods. The after() method returns true because date2 comes after date1. The before() method returns false because date2 does not come before date1. By the end of this post, we hope you have got yourself familiarized with the java.util.Date class in Java.
Find elsewhere
🌐
Jenkov
jenkov.com › tutorials › java-date-time › java-util-date.html
Java's java.util.Date
You can also create a java.util.Date from a time in milliseconds, like this:
Top answer
1 of 3
4

Just follow the javadoc, as it says:

public String toString()

Converts this Date object to a String of the form:

dow mon dd hh:mm:ss zzz yyyy

zzz is the time zone (and may reflect daylight saving time).

And when you dive into the source code, that this toString() implementation will at some point use TimeZone.getDefault() ( or to be precise: getDefaultRef()). In other words: the default implementation pulls in the "default" timezone of your JVM.

2 of 3
3

tl;dr

Current moment in UTC.

Instant.now()    // Capture current moment in UTC.
    .toString()  // Generate String in standard ISO 8601 format.

2018-01-23T01:23:45.677340Z

Current moment in India time zone.

ZonedDateTime.now( 
    ZoneId.of( "Asia/Kolkata" ) 
).toString()    // Generate string in format wisely extended from ISO 8601 standard, adding the time zone name in square brackets.

2018-01-23T06:53:45.677340+05:30[Asia/Kolkata]

Avoid legacy date-time classes

Why does java.util.Date object show date & time with respect to a timezone when in actuality, java.util.Date represents an instant on the time-line, not a "date"?

Because the java.util.Date and related classes (Calendar, SimpleDateFormat, and such) are poorly-designed. While a valiant effort at tackling the tricky subject of date-time handling, they fall short of the goal. They are riddled with poor design choices. You should avoid them, as they are now supplanted by the java.time classes, an enormous improvement.

Specifically to answer your question: The toString method of Date dynamically applies the JVM’s current default time zone while generating a String. So while the Date object itself represents a moment in UTC, the toString creates the false impression that it carries the displayed time zone.

Even worse, there is a time zone buried inside the Date object. That zone is used internally, yet is irrelevant to our discussion here. Confusing? Yes, yet another reason to avoid this class.

A java.util.Date instance has no concept of time-zone.

Not true. A Date represents a specific moment, a point on the timeline, with a resolution of milliseconds, in UTC. As you mention, it is defined as a count of milliseconds since the first moment of 1970 in UTC.

java.time

The java.time classes separate clearly the concepts of UTC, zoned, and unzoned values.

The java.time.Instant class represents a moment on the timeline in UTC with a resolution of nanoseconds (up to nine (9) digits of a decimal fraction). This class replaces java.util.Date.

Instant instant = Instant.now() ;  // Capture current moment in UTC.

Apply a time zone (ZoneId object) to an Instant and you get a ZonedDateTime object. That class replaces the java.util.Calendar class.

ZoneId z = ZoneId.of( "Asia/Kolkata" ) ;
ZonedDateTime zdt = instant.atZone( z ) ;  // Same simultaneous moment as `instant`, but different wall-clock time.

If a value has only an offset-from-UTC but not a full time zone, use the OffsetDateTime class.

For a date only, without time-of-day and without time zone, use the LocalDate class. This class replaces the java.sql.Date class. Ditto for LocalTime replacing java.sql.Time.

LocalDate xmasDate2018 = LocalDate.of( 2018 , Month.DECEMBER , 25 ) ;

If the zone or offset are unknown or indeterminate, such as "Christmas starts at stroke of midnight on December 25, 2018", use the LocalDateTime class. This class does not represent an actual moment, a specific point on the timeline. This class lacks any concept of time zone or offset. So it can only represent potential moments along a range of about 26-27 hours.

LocalDateTime xmasEverywhere2018 = LocalDateTime.of( xmasDate2018 , LocalTime.MIN ) ;

Or…

LocalDateTime xmasEverywhere2018 = LocalDateTime.of( 2018 , Month.DECEMBER , 25 , 0 , 0 , 0 , 0 ) ;

About java.time

The java.time framework is built into Java 8 and later. These classes supplant the troublesome old legacy date-time classes such as java.util.Date, Calendar, & SimpleDateFormat.

The Joda-Time project, now in maintenance mode, advises migration to the java.time classes.

To learn more, see the Oracle Tutorial. And search Stack Overflow for many examples and explanations. Specification is JSR 310.

With a JDBC driver complying with JDBC 4.2 or later, you may exchange java.time objects directly with your database. No need for strings or java.sql.* classes.

Where to obtain the java.time classes?

  • Java SE 8, Java SE 9, and later
    • Built-in.
    • Part of the standard Java API with a bundled implementation.
    • Java 9 adds some minor features and fixes.
  • Java SE 6 and Java SE 7
    • Much of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
  • Android
    • Later versions of Android bundle implementations of the java.time classes.
    • For earlier Android, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above). See How to use ThreeTenABP….

The ThreeTen-Extra project extends java.time with additional classes. This project is a proving ground for possible future additions to java.time. You may find some useful classes here such as Interval, YearWeek, YearQuarter, and more.

🌐
Dariawan
dariawan.com › tutorials › java › java-date-examples
Java Date Examples | Dariawan
Date is sufficient if we need only ... one hour later, etc). For dates operation, we can use java.util.Calendar which allow us to extract year, month, day, hour, minute, and second, and manipulating these field · Date is legacy class, which does not support international...
🌐
Tutorialspoint
tutorialspoint.com › java › java_date_time.htm
Java - Date and Time
The index must immediately follow ... { // Instantiate a Date object Date date = new Date(); // display time and date System.out.printf("%1$s %2$tB %2$td, %2$tY", "Due date:", date); } }...
🌐
Coderanch
coderanch.com › t › 389344 › java › java-util-Date
java.util.Date (Beginning Java forum at Coderanch)
(actually, I'm feeling a bit depreKated ... SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy"); try { Date d = sdf.parse("02-05-1999"); System.out.println(d); } catch (ParseException e) { System.out.println("whoops"); } } } reply reply ·...
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ... Java does not have a built-in Date class, but we can import the java.time package to work with the date and time API.
🌐
Medium
medium.com › codex › java-date-format-5a2515b07c2c
Java Date Format with Examples. java. util.Date | by Maneesha Nirman | CodeX | Medium
November 12, 2022 - ... This constructor initializes ... local machine or server. import java.util.Date;public class A {public static void main(String[] args) {Date date = new Date(); System.out.println(date); } }...
🌐
Scaler
scaler.com › home › topics › java.util.date class
java. util.Date Class - Scaler Topics
December 13, 2022 - We need to import the java.util.date class to include its methods in our code. The Java util date class represents a particular moment in time with millisecond precision elapsed since 1st January 1970 00:00:00 GMT.
🌐
GeeksforGeeks
geeksforgeeks.org › java › date-class-java-examples
Date class in Java (With Examples) - GeeksforGeeks
January 2, 2019 - // Program to demonstrate methods ... args) { // Creating date Date d1 = new Date(2000, 11, 21); Date d2 = new Date(); // Current date Date d3 = new Date(2010, 1, 3); boolean a = d3.after(d1); System.out.println("Date ...
🌐
Medium
medium.com › @programmingsolutions750 › in-java-java-util-date-08f6cc52b954
java.util.Date vs java.time.LocalDate in Java: Which One Should You Use in the Java DateTime API | by FullStack With Ram | Medium
April 5, 2025 - Thread Safety: Date is not thread-safe, ... a new Date object with the current date and time Date date = new Date(); System.out.println("Current Date: " + date); } }...
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › Date.html
Date (Java Platform SE 7 )
Because of the manner in which ... to methods for these purposes need not fall within the indicated ranges; for example, a date may be specified as January 32 and is interpreted as meaning February 1....