You probably have some other "Date" class imported somewhere (or you have a Date class in you package, which does not need to be imported). With "import java.util.*" you are using the "other" Date. In this case it's best to explicitly specify java.util.Date in the code.

Or better, try to avoid naming your classes "Date".

Answer from sleske on Stack Overflow
🌐
CodeGym
codegym.cc › java blog › java classes › java.util.date class
Java.util.Date Class
February 14, 2025 - This java.util.Date constructor ... import java.util.Date; public class Example1 { public static void main(String[] args) { long ms = System.currentTimeMillis(); Date date = new Date(ms); System.out.println(date); } }...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › › › › java › util › Date.html
Date (Java Platform SE 8 )
October 20, 2025 - This Date object is modified so that it represents a point in time within the specified minute of the hour, with the year, month, date, hour, and second the same as before, as interpreted in the local time zone. ... Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.SECOND). Returns the number of seconds past the minute represented by this date. The value returned is between 0 and 61. The values 60 and 61 can only occur on those Java Virtual Machines that take leap seconds into account.
🌐
GeeksforGeeks
geeksforgeeks.org › java › util-date-class-methods-java-examples
util.date class methods in Java with Examples - GeeksforGeeks
September 8, 2021 - // JAVA program explaining Date class methods // after(), clone(), before() import java.util.Date; public class NewClass { public static void main(String[] args) { // create 2 dates Date date1 = new Date(2016, 11, 18); Date date2 = new Date(1997, ...
🌐
Tutorialspoint
tutorialspoint.com › java › java_date_time.htm
Java - Date and Time
It would be a bit silly if you had to supply the date multiple times to format each part. For that reason, a format string can indicate the index of the argument to be formatted. The index must immediately follow the % and it must be terminated by a $. import java.util.Date; public class DateDemo { public static void main(String args[]) { // 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); } }
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
To display the current date and time, import the java.time.LocalDateTime class, and use its now() method: import java.time.LocalDateTime; // import the LocalDateTime class public class Main { public static void main(String[] args) { LocalDateTime ...
🌐
EDUCBA
educba.com › home › software development › software development tutorials › java tutorial › java.util.date
java.util.Date | Understanding the Concept and Programming Examples
May 10, 2024 - Below are the examples of java.util.Date: Code: import java.time.Instant; import java.util.Date; public class Example { public static void main(String[] args) { //an instance of the date class is created which stores the present date Date dat=new ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
TutorialsPoint
tutorialspoint.com › java › util › java_util_date.htm
Java Date Class
Following is the declaration for ... instance of current time. package com.tutorialspoint; import java.time.Instant; // Import the Date package import java.util.Date; // Main public class public class DateDemo { public static void main(String[] args) { // create a date of current ...
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › date-class-java-examples
Date class in Java (With Examples) - GeeksforGeeks
January 2, 2019 - // Java program to demonstrate constuctors of Date import java.util.*; public class Main { public static void main(String[] args) { Date d1 = new Date(); System.out.println("Current date is " + d1); Date d2 = new Date(2323223232L); ...
🌐
Scaler
scaler.com › home › topics › java.util.date class
java. util.Date Class - Scaler Topics
December 13, 2022 - The java. util. The date is a class that is inside java. util package. We need to import the java.
🌐
GitHub
github.com › openjdk-mirror › jdk7u-jdk › blob › master › src › share › classes › java › util › Date.java
jdk7u-jdk/src/share/classes/java/util/Date.java at master · openjdk-mirror/jdk7u-jdk
* or visit www.oracle.com if you need additional information or have any · * questions. */ · package java.util; · import java.text.DateFormat; import java.io.IOException; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.lang.ref.SoftReference; import sun.util.calendar.BaseCalendar; import sun.util.calendar.CalendarDate; import sun.util.calendar.CalendarSystem; import sun.util.calendar.CalendarUtils; import sun.util.calendar.Era; import sun.util.calendar.Gregorian; import sun.util.calendar.ZoneInfo; ·
Author   openjdk-mirror
Top answer
1 of 9
168

Gotcha: passing 2 as month may give you unexpected result: in Calendar API, month is zero-based. 2 actually means March.

I don't know what is an "easy" way that you are looking for as I feel that using Calendar is already easy enough.

Remember to use correct constants for month:

 Date date = new GregorianCalendar(2014, Calendar.FEBRUARY, 11).getTime();

Another way is to make use of DateFormat, which I usually have a util like this:

 public static Date parseDate(String date) {
     try {
         return new SimpleDateFormat("yyyy-MM-dd").parse(date);
     } catch (ParseException e) {
         return null;
     }
  }

so that I can simply write

Date myDate = parseDate("2014-02-14");

Yet another alternative I prefer: Don't use Java Date/Calendar anymore. Switch to JODA Time or Java Time (aka JSR310, available in JDK 8+). You can use LocalDate to represent a date, which can be easily created by

LocalDate myDate =LocalDate.parse("2014-02-14");
// or
LocalDate myDate2 = new LocalDate(2014, 2, 14);
// or, in JDK 8+ Time
LocalDate myDate3 = LocalDate.of(2014, 2, 14);
2 of 9
80

tl;dr

LocalDate.of( 2014 , 2 , 11 )

If you insist on using the terrible old java.util.Date class, convert from the modern java.time classes.

java.util.Date                        // Terrible old legacy class, avoid using. Represents a moment in UTC. 
.from(                                // New conversion method added to old classes for converting between legacy classes and modern classes.
    LocalDate                         // Represents a date-only value, without time-of-day and without time zone.
    .of( 2014 , 2 , 11 )              // Specify year-month-day. Notice sane counting, unlike legacy classes: 2014 means year 2014, 1-12 for Jan-Dec.
    .atStartOfDay(                    // Let java.time determine first moment of the day. May *not* start at 00:00:00 because of anomalies such as Daylight Saving Time (DST).
        ZoneId.of( "Africa/Tunis" )   // Specify time zone as `Continent/Region`, never the 3-4 letter pseudo-zones like `PST`, `EST`, or `IST`. 
    )                                 // Returns a `ZonedDateTime`.
    .toInstant()                      // Adjust from zone to UTC. Returns a `Instant` object, always in UTC by definition.
)                                     // Returns a legacy `java.util.Date` object. Beware of possible data-loss as any microseconds or nanoseconds in the `Instant` are truncated to milliseconds in this `Date` object.   

Details

If you want "easy", you should be using the new java.time package in Java 8 rather than the notoriously troublesome java.util.Date & .Calendar classes bundled with Java.

java.time

The java.time framework built into Java 8 and later supplants the troublesome old java.util.Date/.Calendar classes.

Date-only

A LocalDate class is offered by java.time to represent a date-only value without any time-of-day or time zone. You do need a time zone to determine a date, as a new day dawns earlier in Paris than in Montréal for example. The ZoneId class is for time zones.

ZoneId zoneId = ZoneId.of( "Asia/Singapore" );
LocalDate today = LocalDate.now( zoneId );

Dump to console:

System.out.println ( "today: " + today + " in zone: " + zoneId );

today: 2015-11-26 in zone: Asia/Singapore

Or use a factory method to specify the year, month, day.

LocalDate localDate = LocalDate.of( 2014 , Month.FEBRUARY , 11 );

localDate: 2014-02-11

Or pass a month number 1-12 rather than a DayOfWeek enum object.

LocalDate localDate = LocalDate.of( 2014 , 2 , 11 );

Time zone

A LocalDate has no real meaning until you adjust it into a time zone. In java.time, we apply a time zone to generate a ZonedDateTime object. That also means a time-of-day, but what time? Usually makes sense to go with first moment of the day. You might think that means the time 00:00:00.000, but not always true because of Daylight Saving Time (DST) and perhaps other anomalies. Instead of assuming that time, we ask java.time to determine the first moment of the day by calling atStartOfDay.

Specify a proper time zone name in the format of continent/region, such as America/Montreal, Africa/Casablanca, or Pacific/Auckland. Never use the 3-4 letter abbreviation such as EST or IST as they are not true time zones, not standardized, and not even unique(!).

ZoneId zoneId = ZoneId.of( "Asia/Singapore" );
ZonedDateTime zdt = localDate.atStartOfDay( zoneId );

zdt: 2014-02-11T00:00+08:00[Asia/Singapore]

UTC

For back-end work (business logic, database, data storage & exchange) we usually use UTC time zone. In java.time, the Instant class represents a moment on the timeline in UTC. An Instant object can be extracted from a ZonedDateTime by calling toInstant.

Instant instant = zdt.toInstant();

instant: 2014-02-10T16:00:00Z

Convert

You should avoid using java.util.Date class entirely. But if you must interoperate with old code not yet updated for java.time, you can convert back-and-forth. Look to new conversion methods added to the old classes.

java.util.Date d = java.util.from( instant ) ;

…and…

Instant instant = d.toInstant() ;


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.

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

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

You may exchange java.time objects directly with your database. Use a JDBC driver compliant with JDBC 4.2 or later. No need for strings, no need for java.sql.* classes. Hibernate 5 & JPA 2.2 support java.time.

Where to obtain the java.time classes?

  • Java SE 8, Java SE 9, Java SE 10, Java SE 11, and later - Part of the standard Java API with a bundled implementation.
    • Java 9 brought some minor features and fixes.
  • Java SE 6 and Java SE 7
    • Most of the java.time functionality is back-ported to Java 6 & 7 in ThreeTen-Backport.
  • Android
    • Later versions of Android (26+) bundle implementations of the java.time classes.
    • For earlier Android (<26), a process known as API desugaring brings a subset of the java.time functionality not originally built into Android.
      • If the desugaring does not offer what you need, the ThreeTenABP project adapts ThreeTen-Backport (mentioned above) to Android. See How to use ThreeTenABP….

UPDATE: The Joda-Time library is now in maintenance mode, and advises migration to the java.time classes. I am leaving this section in place for history.

Joda-Time

For one thing, Joda-Time uses sensible numbering so February is 2 not 1. Another thing, a Joda-Time DateTime truly knows its assigned time zone unlike a java.util.Date which seems to have time zone but does not.

And don't forget the time zone. Otherwise you'll be getting the JVM’s default.

DateTimeZone timeZone = DateTimeZone.forID( "Asia/Singapore" );
DateTime dateTimeSingapore = new DateTime( 2014, 2, 11, 0, 0, timeZone );
DateTime dateTimeUtc = dateTimeSingapore.withZone( DateTimeZone.UTC );

java.util.Locale locale = new java.util.Locale( "ms", "SG" ); // Language: Bahasa Melayu (?). Country: Singapore.
String output = DateTimeFormat.forStyle( "FF" ).withLocale( locale ).print( dateTimeSingapore );

Dump to console…

System.out.println( "dateTimeSingapore: " + dateTimeSingapore );
System.out.println( "dateTimeUtc: " + dateTimeUtc );
System.out.println( "output: " + output );

When run…

dateTimeSingapore: 2014-02-11T00:00:00.000+08:00
dateTimeUtc: 2014-02-10T16:00:00.000Z
output: Selasa, 2014 Februari 11 00:00:00 SGT

Conversion

If you need to convert to a java.util.Date for use with other classes…

java.util.Date date = dateTimeSingapore.toDate();
🌐
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, which makes it tricky to use in multi-threaded environments. import java.util.Date; public class DateExample { public static void main(String[] args) { // Create a new Date object with the current date ...
🌐
Codecademy
codecademy.com › docs › java › date
Java | Date | Codecademy
June 21, 2023 - Beginner Friendly.Beginner Friendly17 hours17 hours · import java.util.Date; public class DateExample { public static void main(String[] args) { Date currentDate = new Date(); long currentTimeMillis = currentDate.getTime(); System.out.prin...
🌐
Coderanch
coderanch.com › t › 250809 › certification › Import-java-sql-Date-java
Can we Import java.sql.Date and java.util.Date in one java class (OCPJP forum at Coderanch)
if you want to use both in one class, then import one with: import java.sql.Date; and refer to the other one using fully qualified name ... import java.util.Date; class testImport { // This is from java.util.Date Date todayUtilDate; //This is from java.sql.Date java.sql.Date todaySqlDate; public ...
🌐
Coderanch
coderanch.com › t › 391255 › java › import-java-util-date
import java.util.date; (Beginning Java forum at Coderanch)
Some other helpful classes to go along with Date. GregorianCalendar, SimpleDateFormat and Calendar. ... Bem-vindo, Ronildo. Do you have some examples or study aids of how it uses that class to order for e-mail? Here is an assignment which requires the use of the java.util.Date class.
🌐
GT/CoC
sites.cc.gatech.edu › computing › pag › tmp › html_dir › java › util › Date.java.html
java.util.Date (Java2HTML)
import java.lang.ref.SoftReference; 15 · import sun.util.calendar.BaseCalendar; 16 · import sun.util.calendar.CalendarDate; 17 · import sun.util.calendar.CalendarSystem; 18 · import sun.util.calendar.CalendarUtils; 19 · import sun.util.calendar.Era; 20 · import sun.util.calendar.Gregorian; 21 · import sun.util.calendar.ZoneInfo; 22 · 23 · /** 24 * The class <code>Date</code> represents a specific instant ·
🌐
Classpath
developer.classpath.org › doc › java › util › Date-source.html
Source for java.util.Date (GNU Classpath 0.95 Documentation)
*/ 37: 38: package java.util; 39: ... import java.text.DateFormat; 45: import java.text.SimpleDateFormat; 46: 47: /** 48: * <p> 49: * This class represents a specific time in ......
🌐
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); } }...