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); } }
🌐
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 - A Date instance represents the time spent since Epach in milliseconds. If we print the date instance, it always prints the default or local timezone of the machine. So the timezone information printed in Date.toString() method should not misguide you. Java program of formatting Date to string using SimpleDateFormat.format().
🌐
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 ...
🌐
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!
🌐
Jenkov
jenkov.com › tutorials › java-internationalization › simpledateformat.html
Java SimpleDateFormat
The Date instance passed to the format() method is a java.util.Date instance.
🌐
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
🌐
Edureka
edureka.co › blog › date-format-in-java
Date Format In Java | Java Simple Date Format | Edureka
July 23, 2024 - Let us now look at some examples for different formats of date and time. ... Parsing is the conversion of String into a java.util.Date instance. We can parse a string to a date instance using parse() method of 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 calculations.
🌐
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.
🌐
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.
🌐
Oracle
docs.oracle.com › javase › 7 › docs › api › java › text › DateFormat.html
DateFormat (Java Platform SE 7 )
7 ... 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.
🌐
Javatpoint
javatpoint.com › java-simpledateformat
Java SimpleDateFormat
java.util.Date · java.sql.Date · Java Calendar · Java TimeZone · DateFormat · SimpleDateFormat · Get Current Date Time · Java Date Format There are two classes for formatting dates in Java: and Simple. The java.text. class provides various methods to format and parse date and time in java in language-independent manner.
🌐
Microsoft Learn
learn.microsoft.com › en-us › dotnet › api › java.text.dateformat.format
DateFormat.Format Method (Java.Text) | Microsoft Learn
Microsoft makes no warranties, express or implied, with respect to the information provided here. Formats a Date into a date-time string. [Android.Runtime.Register("format", "(Ljava/util/Date;)Ljava/lang/String;", "")] public string ...
🌐
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.
🌐
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.
🌐
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
🌐
Scaler
scaler.com › topics › date-format-in-java
Date Format in Java - Scaler Topics
April 20, 2022 - Call the format() method of SimpleDateFormat without going through the Date object; this method returns a String representation of the specified date ... Parsing is the process of converting Strings into Java.util.Date instances.