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);
Answer from Adrian Shum on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › java › date-class-java-examples
Date class in Java (With Examples) - GeeksforGeeks
January 2, 2019 - Date(long milliseconds) : Creates a date object for the given milliseconds since January 1, 1970, 00:00:00 GMT. ... Date(String s) Note : The last 4 constructors of the Date class are Deprecated. ... // 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); System.out.println("Date represented is "+ d2 ); } } ...
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › › › › java › util › Date.html
Date (Java Platform SE 8 )
October 20, 2025 - In all cases, arguments given 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. ... Allocates a Date object and initializes it so that it represents the time at which it was ...
🌐
Tutorialspoint
tutorialspoint.com › java › java_date_time.htm
Java - Date and Time
You can use the methods before( ), after( ), and equals( ). Because the 12th of the month comes before the 18th, for example, new Date(99, 2, 12).before(new Date (99, 2, 18)) returns true.
🌐
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.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › util › Date.html
Date (Java Platform SE 7 )
In all cases, arguments given 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. ... Allocates a Date object and initializes it so that it represents the time at which it was ...
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();
🌐
Oracle
docs.oracle.com › javame › config › cldc › ref-impl › cldc1.0 › jsr030 › java › util › Date.html
java.util Class Date
Most computer clocks are not accurate enough to be able to reflect the leap-second distinction. ... Allocates a Date object and initializes it to represent the current time specified number of milliseconds since the standard base time known as "the epoch", namely January 1, 1970, 00:00:00 GMT.
🌐
Codecademy
codecademy.com › docs › java › date
Java | Date | Codecademy
June 21, 2023 - In the above code, the Date class is imported from the java.util package. Inside the main method, currentDate is assigned the current date and time. Next, the .getTime() method is used to return the number of milliseconds since the epoch. Finally, both values are logged to the console. Here are some important aspects and methods of the Date class: ... Date(): Creates an object representing the current date and time.
Find elsewhere
🌐
Medium
medium.com › @alxkm › how-to-work-with-dates-in-java-a-complete-guide-203b7e657648
How to Work with Dates in Java: A Complete Guide | by Alex Klimenko | Medium
August 9, 2025 - Example: import java.time.LocalDate; import java.time.format.DateTimeFormatter; LocalDate date = LocalDate.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy"); String formattedDate = date.format(formatter); System.out.println(formattedDate); // Outputs something like "31-05-2025" DateTimeFormatter supports flexible patterns and can be used with all java.time classes. To parse a date string into a date object: import java.time.LocalDate; import java.time.format.DateTimeFormatter; String dateString = "31-05-2025"; ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.date
Date Class (Java.Util) | Microsoft Learn
[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
🌐
InfluxData
influxdata.com › home › java date format: a detailed guide
Java Date Format: A Detailed Guide | InfluxData
July 12, 2024 - See below for a practical example ... args) { // Creating a Date object representing the current date and time Date currentDate = new Date(); // Printing the current date and time represented by the Date object System.out.p...
Top answer
1 of 2
9

tl;dr

I want a Date object to be included in a Magazine object so that I can know when was the Magazine published.

So add a member variable of type java.time.LocalDate.

package work.basil.example;

import java.time.LocalDate;

public class Magazine
{
    // Member variables.
    public LocalDate published ;

    // Constructor.
    public Magazine ( LocalDate published )
    {
        this.published = published;
    }
}

To use it:

Magazine m = new Magazine( LocalDate.of( 2019 , Month.JANUARY , 23 ) ) ;

LocalDate

  • The modern approach uses LocalDate.
  • Never use java.util.Date or java.sql.Date.

The LocalDate class represents a date-only value without time-of-day and without time zone or offset-from-UTC.

A time zone is crucial in determining a date. For any given moment, the date varies around the globe by zone. For example, a few minutes after midnight in Paris France is a new day while still “yesterday” in Montréal Québec.

If no time zone is specified, the JVM implicitly applies its current default time zone. That default may change at any moment during runtime(!), so your results may vary. Better to specify your desired/expected time zone explicitly as an argument. If critical, confirm the zone with your user.

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

ZoneId z = ZoneId.of( "America/Montreal" ) ;  
LocalDate today = LocalDate.now( z ) ;

If you want to use the JVM’s current default time zone, ask for it and pass as an argument. If omitted, the code becomes ambiguous to read in that we do not know for certain if you intended to use the default or if you, like so many programmers, were unaware of the issue.

ZoneId z = ZoneId.systemDefault() ;  // Get JVM’s current default time zone.

Or specify a date. You may set the month by a number, with sane numbering 1-12 for January-December.

LocalDate ld = LocalDate.of( 1986 , 2 , 23 ) ;  // Years use sane direct numbering (1986 means year 1986). Months use sane numbering, 1-12 for January-December.

Or, better, use the Month enum objects pre-defined, one for each month of the year. Tip: Use these Month objects throughout your codebase rather than a mere integer number to make your code more self-documenting, ensure valid values, and provide type-safety. Ditto for Year & YearMonth.

LocalDate ld = LocalDate.of( 1986 , Month.FEBRUARY , 23 ) ;


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.

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 adds 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 bundle implementations of the java.time classes.
    • For earlier Android (<26), 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.

2 of 2
0

"Deprecated" refers to functions or elements that are in the process of being replaced by newer ones. Deprecated items may work in the current version of a programming language, they may not function in future updates.

But you can ignore and use it.

Example :

String pattern = "yyyy-MM-dd";
SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern);
String date = simpleDateFormat.format(new Date(1,1,1));
System.out.println(date);

Output :

1901-02-01

But if you don't want to use deprecated methods, you can go for LocalDate :

LocalDate localDate = LocalDate.of(2019, 1, 1);
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
String formatted = localDate.format(dateTimeFormatter);
System.out.println(formatted);

Output :

2019-01-01
🌐
CodeGym
codegym.cc › java blog › java classes › java.util.date class
Java.util.Date Class
February 14, 2025 - This java.util.Date constructor creates a date object the equals the number of milliseconds that have elapsed since January 1, 1970, 00:00:00 GMT. long ms = System.currentTimeMillis(); Date date = new Date(ms); Here, we have initialized the ...
🌐
MIT
web.mit.edu › java_v1.0.2 › www › javadoc › java.util.Date.html
Class java.util.Date
Creates a date. The fields are normalized before the Date object is created. The arguments do not have to be in the correct range. For example, the 32nd of January is correctly interpreted as the 1st of February.
🌐
Dariawan
dariawan.com › tutorials › java › java-date-examples
Java Date Examples | Dariawan
date: Sun Jul 07 11:41:56 SGT 2019 instant1 equals instant2: true date2: Sun Jul 07 11:41:56 SGT 2019 instant3: 2019-07-07T03:41:56.625Z · Please refer to Java 8 Instant Tutorial with Examples.
🌐
Oracle
docs.oracle.com › en › java › javase › 17 › docs › api › java.base › java › util › Date.html
Date (Java SE 17 & JDK 17)
January 20, 2026 - In all cases, arguments given 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. ... Allocates a Date object and initializes it so that it represents the time at which it was ...
Top answer
1 of 5
2

tl;dr

You are passing a String object to your constructor, but then attempting to assign it to a member variable of a different type (Date). No can do. Square peg, round hole. You must first parse that text into an object of the correct type.

Another problem: You are using terrible old date-time class Date where you should be using the modern java.time.LocalDate class.

LocalDate.of( 1994 , Month.JANUARY , 1 )

java.time

I would like to know how to use type Date in new object?

Don’t.

Apparently you want a date-only value, so use a date-only class rather than a date-plus-time-of-day class.

Furthermore, never use java.util.Date. It is part of the troublesome old date-time classes that were supplanted years ago by the java.time classes.

The LocalDate class represents a date-only value without time-of-day and without time zone. Specify the month part either by number 1-12 for January-December or by the Month enum class.

LocalDate ld = LocalDate.of( 1994 , Month.JANUARY , 1 ) ;

Change your member variable:

private Date gbdatum ;

…to:

private LocalDate gbdatum ;

Change your constructor to:

public Reiziger(String nm, LocalDate gbdtm)

Call it like this:

Reiziger r1 = new Reiziger( 
    "Joost" , 
    LocalDate.of( 1994 , Month.JANUARY , 1 ) 
) ;

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.

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.

Where to obtain the java.time classes?

  • Java SE 8, Java SE 9, Java SE 10, 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 (<26), 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.

2 of 5
2

Your method is defined as taking in a Date object, however you are trying to pass in a String. Java does not automatically convert the String to a Date.

What you need to do is use a DateFormatter.

This uses a defined Date pattern to convert your incoming String into the Date object you want to use.

In your case, you would want to do something similar to this:

String dateFormat = "MM-dd-yyyy";

try {
    DateFormat df = new SimpleDateFormat(dateFormat);
    Date dateToUse = df.parse("01-01-1994");

    // Or this way
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(dateFormat);
    LocalDate localDate = LocalDate.parse("01-01-1994", formatter);
} catch (ParseException pe) {
    // Do something
}

Here are the links to the Java PI:
SimpleDateFormatter: https://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html

DateTimeFormatter: https://docs.oracle.com/javase/8/docs/api/java/time/format/DateTimeFormatter.html

LocalDate: https://docs.oracle.com/javase/8/docs/api/java/time/LocalDate.html

🌐
Queen Mary University of London
eecs.qmul.ac.uk › ~mmh › ItP › resources › dates1.html
The Dates Examples: Part 1
Each constructor must have the same name as the class, but the particular constructor used when an object is created depends on the arguments specified in the call. Below is a version of the Dates program which uses the constructor given above, and the toString method to print out the dates: 1 import java.io.*; 2 3 class Dates1 4 { 5 // Read a number of dates and store them in an array.
🌐
Oracle
docs.oracle.com › en › java › javase › 20 › docs › api › java.base › java › util › Date.html
Date (Java SE 20 & JDK 20)
July 10, 2023 - In all cases, arguments given 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. ... Allocates a Date object and initializes it so that it represents the time at which it was ...