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
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › › › › java › util › Date.html
Date (Java Platform SE 8 )
October 20, 2025 - Allocates a Date object and initializes it so that it represents the date and time indicated by the string s, which is interpreted as if by the parse(java.lang.String) method.
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
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. The package includes many date and time classes.
Discussions

What date object type should I use for my java backend
I suggest you store times in epoch time format and figure out displaying on client More on reddit.com
🌐 r/learnprogramming
7
6
August 19, 2025
Which date classes to use in Java ?
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://imgur.com/a/fgoFFis ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
🌐 r/javahelp
8
1
June 15, 2022
How should I handle date objects when the java.util.date constructor I want to use has been deprecated?
represent date using UNIX timestamps. More on reddit.com
🌐 r/learnprogramming
9
0
August 22, 2017
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();
🌐
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 ); } } Output:
🌐
Tutorialspoint
tutorialspoint.com › java › java_date_time.htm
Java - Date and Time
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 using toString() System.out.println(date.toString()); } }
🌐
Baeldung
baeldung.com › home › java › java dates › convert string to date in java
Convert String to Date in Java | Baeldung
March 26, 2025 - By default, Java dates are in the ISO-8601 format, so if we have any string which represents a date and time in this format, then we can use the parse() API of these classes directly. The Date-Time API provides parse() methods for parsing a String that contains date and time information. To convert String objects to LocalDate and LocalDateTime objects, the String must represent a valid date or time according to ISO_LOCAL_DATE or ISO_LOCAL_DATE_TIME.
Find elsewhere
🌐
Jon Skeet's Coding Blog
codeblog.jonskeet.uk › 2017 › 04 › 23 › all-about-java-util-date
All about java.util.Date | Jon Skeet's coding blog
May 23, 2017 - The only cases where I could see ... object… and that’s better handled by using an API that will allow you to write date = new DateFoo(year, month, day). ... There is likewise another entanglement of DateFormat classes like SimpleDateFormat that it you can’t utilize them for parsing in a multi-strung condition. The main safe approach to do it is to develop another one without fail. The new API in Java 8 has string ...
🌐
InfluxData
influxdata.com › home › java date format: a detailed guide
Java Date Format: A Detailed Guide | InfluxData
July 12, 2024 - To convert a string into a date in Java, you can use SimpleDateFormat or DateTimeFormatter to parse the string according to a specified format pattern. The example below demonstrates how to parse a string representing a date (01/31/2024) into a date object using SimpleDateFormat.
🌐
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 ·
🌐
Codecademy
codecademy.com › docs › java › date
Java | Date | Codecademy
June 21, 2023 - Date(long millis): Creates a Date object with the specified number of milliseconds since January 1, 1970, 00:00:00 GMT (the Unix epoch). ... SimpleDateFormat class (from java.text package): Allows formatting and parsing of dates using patterns.
🌐
Reddit
reddit.com › r/learnprogramming › what date object type should i use for my java backend
r/learnprogramming on Reddit: What date object type should I use for my java backend
August 19, 2025 -

Hi everyone, I recently deployed my Java Springboot backend on Render.com. However, after deployment, I noticed that events on my calendar page (frontend built with Next.js) are showing up a few hours off, sometimes even making the events show up on the wrong day. (like before it was 18th 9:00PM and now it is 19th 1:00 AM.

After checking my MongoDB data, I saw that the dates are stored in UTC. I'm not sure if I'm explaing this right but here is what I think: when I had localhost backend, everything rendered fine because I was using LocalDateTime, which used my system's local time. But after deploying, the server uses UTC, so the LocalDateTime no longer reflects my actual timezone and that’s why things are off.

How can I fix this? I read some articles and they said to use OffsetDateTime as the date object type in the backend and then in the frontend i format the date i recieve with the javascript Date object tto get the right date on the calendar.

Is this the right approach or are other approaches better? (i'm not really sure about this as I don't have much experience).

Thanks!

🌐
Oracle
docs.oracle.com › javame › config › cldc › ref-impl › cldc1.0 › jsr030 › java › util › Date.html
java.util Class Date
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.
🌐
GeeksforGeeks
geeksforgeeks.org › java › util-date-class-methods-java-examples
util.date class methods in Java with Examples - GeeksforGeeks
September 8, 2021 - Syntax: public boolean before(Date d) Parameters: d : date Return: true if and only if the instant represented by this Date object is strictly earlier than the instant represented by 'when'; else false Exception: NullPointerException - if when ...
🌐
Coderanch
coderanch.com › t › 731983 › java › Setting-date-time-Date-object
Setting date and time of Date object, separately (Java in General forum at Coderanch)
June 28, 2020 - Mark Richardson wrote:. . . //apparently, I can have one or the other... I can't set time and date separately . . . No, you are creating two different objects and when you create the second you are discarding the first. Which Date class are you using? You know how useless java.util.Date is?
🌐
Reddit
reddit.com › r/javahelp › which date classes to use in java ?
r/javahelp on Reddit: Which date classes to use in Java ?
June 15, 2022 -

Hi everyone,

Some people told me to use "Instant".

But I'm unable to set the exact value I want for an Instant, even when I use methods like withMonth(), etc...

    public Instant toJavaClass(MyDateClass something) {
        Instant bestDate = Instant.now(Clock.systemUTC());
        bestDate.atZone(ZoneOffset.UTC).withMinute(something.getMinute());
        bestDate.atZone(ZoneOffset.UTC).withHour(something.getHour());
        bestDate.atZone(ZoneOffset.UTC).withDayOfMonth(something.getDate());
        bestDate.atZone(ZoneOffset.UTC).withMonth(something.getMonth());
        bestDate.atZone(ZoneOffset.UTC).withYear(something.getYear());

        return bestDate;
    }

Is Temporal more recommended ?

How does it work.

Thanks for your help.

🌐
Baeldung
baeldung.com › home › java › java dates › introduction to the java date/time api
Introduction to the Java Date/Time API | Baeldung
October 13, 2023 - In the following two code examples, we parse the date “2016-06-12” and get the day of the week and the day of the month respectively. Note the return values — the first is an object representing the DayOfWeek, while the second is an int representing the ordinal value of the month:
🌐
Coderanch
coderanch.com › t › 559035 › java › previous-Date-java-sql-Date
how can i get previous Date from java.sql.Date object (Beginning Java forum at Coderanch)
November 17, 2011 - A Date object only holds a single date. Edit: if what you mean is that you want to recreate the String value you parsed the date from, then I'd suggest looking at the SimpleDateFormat class - that's the easiest way of converting from Strings to Dates and back again (because a java.sql.Data IS-A java.util.Date it can be used with those as well).
🌐
Programming Hints
programminghints.com › home › still using java.util.date? don’t!
Still using java.util.Date? Don't! - Programming Hints
June 23, 2017 - There are many workarounds in the Java world around this banal design decision, like handling years before 1900. Months are zero indexed (0 – January, 11 – December). Not very intuitive and led to many off-by-one errors. All classes in this old API are mutable. As a result, any time you want to give a date back (say, as an instance structure) you need to return a clone of that date instead of the date object ...
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.util.date.-ctor
Date Constructor (Java.Util) | Microsoft Learn
Allocates a Date object and initializes it so that it represents midnight, local time, at the beginning of the day specified by the year, month, and date arguments. This member is deprecated.
🌐
Medium
medium.com › @ayoubseddiki132 › why-you-should-stop-using-java-util-date-a-complete-guide-to-modern-java-date-time-api-e15a2315e46c
Why You Should Stop Using java.util.Date: A Complete Guide to Modern Java Date-Time API | by Ayoub seddiki | Medium
February 7, 2025 - By switching to java.time, you'll write more maintainable code, avoid common pitfalls, and have access to a rich set of features for date and time manipulation.