DateFormat dffrom = new SimpleDateFormat("M/dd/yyyy");
DateFormat dfto = new SimpleDateFormat("yyyy-MM-dd");  
Date today = dffrom.parse("7/1/2011");
String s = dfto.format(today);

Convert the String to Date first.

Answer from Jacob on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_date.asp
Java Date and Time
import java.time.LocalDateTime; ... " + myDateObj); DateTimeFormatter myFormatObj = DateTimeFormatter.ofPattern("dd-MM-yyyy HH:mm:ss"); String formattedDate = myDateObj.format(myFormatObj); System.out.println("After ...
Discussions

Java How to Display Datetime in String in (mmddyyyyHHMISS) Format - Programming & Development - Spiceworks Community
I need to display a string as MMDDYYYYHHMISS. Example Jan 02 2012 9:01:59 as 01022012090159. I am new to Java . Please advise Thanks in advance. More on community.spiceworks.com
🌐 community.spiceworks.com
0
March 15, 2012
how to format String to Date with format dd-mm-yyyy in java - Stack Overflow
I need some support. I desired convert a variable String to Date. The variable Date should be format dd-MM-yyyy. import java.util.Date; .... ... String a = "2022-05-12"; ... More on stackoverflow.com
🌐 stackoverflow.com
noobie: how to change datepicker format from dd/mm/yyyy to mm/dd/yyyy without using java or css. just html.
in essence, you don't and you shouldn't. the way the value is rendered in the input element is based on web browser and operating system settings. the value exposed to javascript will be normalized into "yyyy-MM-dd" format. Update Output More on reddit.com
🌐 r/AskProgrammers
3
3
July 13, 2024
CMV: YYYY-MM-DD is the superior date format
There is something to be said for presenting the most useful information first. We typically don't need to say the year. For example, If i told you I was going to do something January 10th, you would know what I mean. We also don't ways need to say the month. If i told you i'd do something on the 21st, you'd assume i'm meant the 21st of this month. So we we start with the most relevant information first, there a decent debate to be had over whether we should say the day or the month first. But definitely the year is not very relevant. Very often we only need MM/DD or DD/MM. YYYY/xx/xx is a waste of some space. Especially when speaking. In terms of sorting, most of the time dates are stores as dates and rendered in any format selected. So you can sort properly regardless of format. YYYY-MM-DD has its place. Its good when communicating between different applications which don't share a common data structure. Like between Excel and a database. Its also good when embedded into text fields which you want to sort. Although really you shouldn't be doing that. More on reddit.com
🌐 r/changemyview
101
26
December 13, 2018
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);
🌐
Spiceworks
community.spiceworks.com › programming & development
Java How to Display Datetime in String in (mmddyyyyHHMISS) Format - Programming & Development - Spiceworks Community
March 15, 2012 - I need to display a string as MMDDYYYYHHMISS. Example Jan 02 2012 9:01:59 as 01022012090159. I am new to Java . Please advise Thanks in advance.
🌐
TutorialsPoint
tutorialspoint.com › format-date-with-simpledateformat-mm-dd-yy-in-java
Format date with SimpleDateFormat('MM/dd/yy') in Java
June 26, 2020 - The format() method is called with different date patterns, including custom ones like "yyyy/MM/dd", "dd-M-yyyy hh:mm:ss", and "dd MMMM yyyy zzzz". After formatting, the date is printed in each format.
🌐
Quora
quora.com › What-is-the-code-for-changing-string-to-date-MM-DD-YYYY-H24-MI-SS-formate-in-Java
What is the code for changing string to date (MM/DD/YYYY H24:MI:SS) formate in Java? - Quora
Answer: To convert String to Date in java use java.text.SimpleDateFormat class. sample Code [code] SimpleDateFormat formatter = new SimpleDateFormat("MMM dd, yyyy"); String dateInString = "Jun 7, 2013"; try { Date date = formatter.parse(dat...
Find elsewhere
🌐
Oreate AI
oreateai.com › blog › java-date-formatting-from-yyyymmdd-to-mmddyyyy-with-ease › 333772b959bf410b3844504f14394ede
Java Date Formatting: From YYYY-MM-DD to MM/DD/YYYY With Ease - Oreate AI Blog
1 month ago - import java.time.LocalDate; import java.time.format.DateTimeFormatter; public class ModernDateConverter { public static void main(String[] args) { String originalDate = "2023-10-27"; // Define the input formatter DateTimeFormatter inputFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); // Parse the original string into a LocalDate object LocalDate date = LocalDate.parse(originalDate, inputFormatter); // Define the output formatter DateTimeFormatter outputFormatter = DateTimeFormatter.ofPattern("MM/dd/yyyy"); // Format the LocalDate object into the desired string String convertedDate = date.format(outputFormatter); System.out.println("Original Date: " + originalDate); System.out.println("Converted Date: " + convertedDate); } }
🌐
Jenkov
jenkov.com › tutorials › java-internationalization › simpledateformat.html
Java SimpleDateFormat
Here is an example: String pattern = "EEEEE dd MMMMM yyyy HH:mm:ss.SSSZ"; SimpleDateFormat simpleDateFormat = new SimpleDateFormat(pattern, new Locale("da", "DK")); String date = simpleDateFormat.format(new Date()); System.out.println(date);
🌐
Crown
ccgit.crown.edu › cyber-reels › java-date-formatting-dd-mm-yyyy-made-easy-1767646969
Java Date Formatting: Dd MM Yyyy Made Easy
January 6, 2026 - SimpleDateFormat formatter = new SimpleDateFormat("dd MMM yyyy"); Experiment with different patterns to get the exact date format you need! The beauty of SimpleDateFormat lies in its flexibility.
🌐
Coderanch
coderanch.com › t › 554892 › databases › convert-date-MM-dd-yyyy
Best way to convert date from MM/dd/yyyy to yyyy-mm-dd ? (JDBC and Relational Databases forum at Coderanch)
October 6, 2011 - Now, i convert the String (date recieved from user) to (yyyy-mm-dd) format by using the following java code , send it to valueOf() method of java.sql.Date class and then storing into DB.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-format-javascript-date-as-yyyy-mm-dd
How To Format JavaScript Date as yyyy-mm-dd? - GeeksforGeeks
June 24, 2025 - We use JavaScript built-in help methods from the Date class that help us to create a formatted version of the current date in the form of yyyy-mm-dd.
🌐
Wikipedia
en.wikipedia.org › wiki › ISO_8601
ISO 8601 - Wikipedia
1 week ago - Calendar date representations are in the form shown in the adjacent box. [YYYY] indicates a four-digit year, 0000 through 9999. [MM] indicates a two-digit month of the year, 01 through 12.
🌐
Quora
quora.com › How-do-you-get-a-yyyy-mm-dd-format-in-Java
How to get a yyyy-mm-dd format in Java - Quora
Java has a full set of codes for formatting dates and times: ... Year (e.g. 12 or 2012). Use either yy or yyyy. ... Month in year. Number of M's determine length of format (e.g. MM, MMM or MMMMM) ... Day in month. Number of d's determine length of format (e.g. d or dd)
🌐
Java Guides
javaguides.net › 2024 › 05 › java-get-date-in-yyyy-mm-dd-format.html
Java: Get Date in yyyy-MM-dd Format
May 29, 2024 - DateTimeFormatter.ofPattern("yyyy-MM-dd"): Creates a formatter using the specified pattern. currentDate.format(formatter): Formats the current date using the specified formatter. ... For applications that need to be compatible with Java 7 or ...
🌐
Pega
support.pega.com › discussion › do-not-use-yyyy-uppercase-java-date-formatting
Do not use YYYY (uppercase) in Java date formatting | Support Center
December 29, 2021 - In general, you should almost always (in 99% of use cases) use the calendar year - "yyyy". In my opinion, this new specification post Java 7 is very confusing, and I would advise you to add some form of linting or checking to make sure your code does not have any date formats referencing "YYYY".
🌐
Medium
medium.com › @345490675 › the-yyyy-mm-dd-format-trap-db54d7daa804
The “YYYY-MM-dd” Format Trap
January 9, 2025 - In Java’s date formatting, both y and Y are used to represent the year, but they have essential differences: y represents “year-of-era”, which means “the genuine year.” It strictly follows the Gregorian calendar to calculate the year, starting from New Year’s Day (January 1st) and ending on New Year’s Eve (December 31st). Therefore, when using yyyy to format December 31, 2024, the output result is 2024–12–31, which is consistent with our common understanding.
🌐
Baeldung
baeldung.com › home › java › java dates › convert string to date in java
Convert String to Date in Java | Baeldung
March 26, 2025 - ... <dependency> <groupId>joda... the standard DateTime: DateTimeFormatter formatter = DateTimeFormat.forPattern("dd/MM/yyyy HH:mm:ss"); String dateInString = "07/06/2013 10:11:59"; DateTime dateTime = DateTime.parse(d...
🌐
Java Concept Of The Day
javaconceptoftheday.com › home › how to format date in java?
How To Format Date In Java? - SimpleDateFormat Class With Examples
September 11, 2016 - Formatting the given Date object using SimpleDateFormat class involves two steps. Step 1 : Instantiate SimpleDateFormat class by passing the desired pattern. SimpleDateFormat formatter = new SimpleDateFormat(“dd-MM-yyyy”);