Date is a container for the number of milliseconds since the Unix epoch ( 00:00:00 UTC on 1 January 1970).

It has no concept of format.

Java 8+

LocalDateTime ldt = LocalDateTime.now();
System.out.println(DateTimeFormatter.ofPattern("MM-dd-yyyy", Locale.ENGLISH).format(ldt));
System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(ldt));
System.out.println(ldt);

Outputs...

05-11-2018
2018-05-11
2018-05-11T17:24:42.980

Java 7-

You should be making use of the ThreeTen Backport

Original Answer

For example...

Date myDate = new Date();
System.out.println(myDate);
System.out.println(new SimpleDateFormat("MM-dd-yyyy").format(myDate));
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(myDate));
System.out.println(myDate);

Outputs...

Wed Aug 28 16:20:39 EST 2013
08-28-2013
2013-08-28
Wed Aug 28 16:20:39 EST 2013

None of the formatting has changed the underlying Date value. This is the purpose of the DateFormatters

Updated with additional example

Just in case the first example didn't make sense...

This example uses two formatters to format the same date. I then use these same formatters to parse the String values back to Dates. The resulting parse does not alter the way Date reports it's value.

Date#toString is just a dump of it's contents. You can't change this, but you can format the Date object any way you like

try {
    Date myDate = new Date();
    System.out.println(myDate);

    SimpleDateFormat mdyFormat = new SimpleDateFormat("MM-dd-yyyy");
    SimpleDateFormat dmyFormat = new SimpleDateFormat("yyyy-MM-dd");

    // Format the date to Strings
    String mdy = mdyFormat.format(myDate);
    String dmy = dmyFormat.format(myDate);

    // Results...
    System.out.println(mdy);
    System.out.println(dmy);
    // Parse the Strings back to dates
    // Note, the formats don't "stick" with the Date value
    System.out.println(mdyFormat.parse(mdy));
    System.out.println(dmyFormat.parse(dmy));
} catch (ParseException exp) {
    exp.printStackTrace();
}

Which outputs...

Wed Aug 28 16:24:54 EST 2013
08-28-2013
2013-08-28
Wed Aug 28 00:00:00 EST 2013
Wed Aug 28 00:00:00 EST 2013

Also, be careful of the format patterns. Take a closer look at SimpleDateFormat to make sure you're not using the wrong patterns ;)

Answer from MadProgrammer on Stack Overflow
Top answer
1 of 8
184

Date is a container for the number of milliseconds since the Unix epoch ( 00:00:00 UTC on 1 January 1970).

It has no concept of format.

Java 8+

LocalDateTime ldt = LocalDateTime.now();
System.out.println(DateTimeFormatter.ofPattern("MM-dd-yyyy", Locale.ENGLISH).format(ldt));
System.out.println(DateTimeFormatter.ofPattern("yyyy-MM-dd", Locale.ENGLISH).format(ldt));
System.out.println(ldt);

Outputs...

05-11-2018
2018-05-11
2018-05-11T17:24:42.980

Java 7-

You should be making use of the ThreeTen Backport

Original Answer

For example...

Date myDate = new Date();
System.out.println(myDate);
System.out.println(new SimpleDateFormat("MM-dd-yyyy").format(myDate));
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(myDate));
System.out.println(myDate);

Outputs...

Wed Aug 28 16:20:39 EST 2013
08-28-2013
2013-08-28
Wed Aug 28 16:20:39 EST 2013

None of the formatting has changed the underlying Date value. This is the purpose of the DateFormatters

Updated with additional example

Just in case the first example didn't make sense...

This example uses two formatters to format the same date. I then use these same formatters to parse the String values back to Dates. The resulting parse does not alter the way Date reports it's value.

Date#toString is just a dump of it's contents. You can't change this, but you can format the Date object any way you like

try {
    Date myDate = new Date();
    System.out.println(myDate);

    SimpleDateFormat mdyFormat = new SimpleDateFormat("MM-dd-yyyy");
    SimpleDateFormat dmyFormat = new SimpleDateFormat("yyyy-MM-dd");

    // Format the date to Strings
    String mdy = mdyFormat.format(myDate);
    String dmy = dmyFormat.format(myDate);

    // Results...
    System.out.println(mdy);
    System.out.println(dmy);
    // Parse the Strings back to dates
    // Note, the formats don't "stick" with the Date value
    System.out.println(mdyFormat.parse(mdy));
    System.out.println(dmyFormat.parse(dmy));
} catch (ParseException exp) {
    exp.printStackTrace();
}

Which outputs...

Wed Aug 28 16:24:54 EST 2013
08-28-2013
2013-08-28
Wed Aug 28 00:00:00 EST 2013
Wed Aug 28 00:00:00 EST 2013

Also, be careful of the format patterns. Take a closer look at SimpleDateFormat to make sure you're not using the wrong patterns ;)

2 of 8
37
SimpleDateFormat("MM-dd-yyyy");

instead of

SimpleDateFormat("mm-dd-yyyy");

because MM points Month, mm points minutes

SimpleDateFormat sm = new SimpleDateFormat("MM-dd-yyyy");
String strDate = sm.format(myDate);
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api
Date (Java Platform SE 8 )
October 20, 2025 - JavaScript is disabled on your browser · Frame Alert · This document is designed to be viewed using the frames feature. If you see this message, you are using a non-frame-capable web client. Link to Non-frame version
🌐
Medium
medium.com › codex › java-date-format-5a2515b07c2c
Java Date Format with Examples. java. util.Date | by Maneesha Nirman | CodeX | Medium
November 12, 2022 - Let's have an idea of methods and constructors that can be found in util. Date class. But I am not going to discuss deprecated methods and constructors. ... This constructor initializes and allocates the Date object with the current date and time. It gets time from your 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); } }
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-simpledateformat-java-date-format
Master Java Date Formatting: SimpleDateFormat & DateFormat Guide | DigitalOcean
December 20, 2024 - Master Java date and time formatting with SimpleDateFormat and DateFormat. Learn locale-based patterns and parsing techniques to enhance your java applications!
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
The following example will remove ... " + myDateObj); DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formattedDate = myDateObj.format(myFormatObj); System.out.println("After ...
🌐
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 - Learn to create new date, get current date, parse date to string or format Date object using java.util.Date class.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › text › DateFormat.html
DateFormat (Java Platform SE 8 )
October 20, 2025 - 8 ... DateFormat is an abstract class for date/time formatting subclasses which formats and parses dates or time in a language-independent manner. The date/time formatting subclass, such as SimpleDateFormat, allows for formatting (i.e., date → text), parsing (text → date), and normalization.
🌐
Baeldung
baeldung.com › home › java › java dates › convert java.util.date to string
Convert java.util.Date to String | Baeldung
January 8, 2024 - In this tutorial, we’ll show how we can convert Date objects to String objects in Java. To do so, we’ll work with the older java.util.Date type as well as with the new Date/Time API introduced in Java 8.
Find elsewhere
🌐
Jenkov
jenkov.com › tutorials › java-internationalization › simpledateformat.html
Java SimpleDateFormat
The Java SimpleDateFormat class can parse and format dates according to custom date patterns. This Java SimpleDateFormat tutorial explains how to use the SimpleDateFormat class.
🌐
InfluxData
influxdata.com › home › java date format: a detailed guide
Java Date Format: A Detailed Guide | InfluxData
July 12, 2024 - Java provides several classes and methods for formatting and parsing dates. Let’s explore some of the essential ones: Despite being deprecated, developers still commonly use java.util.Date. It represents a specific instant in time but lacks a specific format and is primarily used for timestamp ...
🌐
Javatpoint
javatpoint.com › java-simpledateformat
Java SimpleDateFormat
Java SimpleDateFormat with concepts and examples of java SimpleDateFormat class, java date format program, java SimpleDateFormat methods, java SimpleDateFormat examples and more.
🌐
Edureka
edureka.co › blog › date-format-in-java
Date Format In Java | Java Simple Date Format | Edureka
July 23, 2024 - A specified date can be formatted into the Data/Time string. The format should be mm/dd/yyyy. According to the Java API, we can set the date using the constructor Date(year, month, day).
🌐
Groovy
docs.groovy-lang.org › latest › html › groovy-jdk › java › util › Date.html
Date (Groovy JDK enhancements)
For example, if the system timezone is GMT, new Date(0).format('MM/dd/yy') would return the string "01/01/70". See documentation for SimpleDateFormat for format pattern use.
🌐
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); } }
🌐
Coderanch
coderanch.com › t › 676462 › java › java-util-Date
A little java.util.Date help [Solved] (Beginning Java forum at Coderanch)
Yes, how can I change the date so it appears in this format? ... If I say to you: "Yesterday, a bit after 1 pm I went lunch". Can you tell me please, how many minutes were after 1 pm? Similar issues are with String you have. [edit] Probably you are asking something slightly different. Apologies if I misunderstood. ... The text passed in to the SimpleDateFormat defines the expected format of the String representation of the date you want to represent.
🌐
Oracle
docs.oracle.com › javase › 8 › docs › api › java › text › SimpleDateFormat.html
SimpleDateFormat (Java Platform SE 8 )
October 20, 2025 - Returns the beginning date of the 100-year period 2-digit years are interpreted as being within. ... Formats the given Date into a date/time string and appends the result to the given StringBuffer.
🌐
Hostman
hostman.com › tutorials › java date format
Java Date Format | Guide by Hostman
March 31, 2025 - Here’s an example demonstrating ... SimpleDateFormat("yyyy-MM-dd"); SimpleDateFormat verboseFormat = new SimpleDateFormat("EEEE, MMMM dd, yyyy"); SimpleDateFormat timeFormat = new SimpleDateFormat("hh:mm a z"); System.out.println("ISO ...
Price   $
Address   1999 Harrison St 1800 9079, 94612, Oakland
🌐
Coderanch
coderanch.com › t › 746130 › java › turn-String-yyyyMM-java-util
How do I turn String yyyyMM into java.util.date? (Java in General forum at Coderanch)
I have String 202104 that I want to turn into Date. So, it means it would be year 2021, month 4 and day 00. ... A day of '0' is invalid - you will get a day of '1' instead which is the first day of the month. ... JavaRanch-FAQ HowToAskQuestionsOnJavaRanch UseCodeTags DontWriteLongLines ItDoesntWorkIsUseLess FormatCode JavaIndenter SSCCE API-17 JLS JavaLanguageSpecification MainIsAPain KeyboardUtility
🌐
Medium
medium.com › @david_turner › java-date-formatting-and-utilization-e2a2e2534049
Java Date Formatting and Utilization | by David Turner | Medium
December 31, 2019 - Java’s Calendar class provides a means of converting Date objects to other instances of times through a slew of methods. Some of these include the obvious, like setting the YEAR, MONTH, DAY_OF_MONTH, etc to other utility based functions like adding or subtracting units of time.
🌐
Jenkov
jenkov.com › tutorials › java-date-time › parsing-formatting-dates.html
Parsing and Formatting Dates in Java
Here is an example of how to format and parse a date using the SimpleDateFormat class. The SimpleDateFormat class works on java.util.Date instances.