Convert a Date to a String using DateFormat#format method:

String pattern = "MM/dd/yyyy HH:mm:ss";

// Create an instance of SimpleDateFormat used for formatting 
// the string representation of date according to the chosen pattern
DateFormat df = new SimpleDateFormat(pattern);

// Get the today date using Calendar object.
Date today = Calendar.getInstance().getTime();        
// Using DateFormat format method we can create a string 
// representation of a date with the defined format.
String todayAsString = df.format(today);

// Print the result!
System.out.println("Today is: " + todayAsString);

From http://www.kodejava.org/examples/86.html

Answer from Ali Ben Messaoud on Stack Overflow
🌐
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.
🌐
InfluxData
influxdata.com › home › how to convert string to date in java
How to Convert String to Date in Java | InfluxData
July 25, 2024 - This example demonstrates how to parse a date string in the format “yyyy-MM-dd” into a Date object. SimpleDateFormat is versatile and supports numerous patterns to match the string representation of dates. With the introduction of the Java 8 Date and Time API, working with dates has become ...
🌐
Educative
educative.io › answers › how-to-convert-string-to-date-in-java-8
How to convert string to date in Java 8
Java 8 provides the LocalDate class and the DateTimeFormatter class to convert a string representation of a date into a LocalDate class object.
🌐
Baeldung
baeldung.com › home › java › java dates › convert string to date in java
Convert String to Date in Java | Baeldung
March 26, 2025 - In this tutorial, we’ll explore several ways to convert String objects into Date objects. We’ll start with the new Date Time API, java.time, that was introduced in Java 8 before looking at the old java.util.Date data type also used for representing dates.
🌐
Coderanch
coderanch.com › t › 692753 › java › Convert-Date-String
Convert Date to a String (Java in General forum at Coderanch)
Number of slices to send: Optional 'thank-you' note: Send · ...wouldn't you want double M and double d? In case I use the MM and dd there is an exception: java.time.format.DateTimeParseException: Text '4/6/2018' could not be parsed at index 0 But, this will work if the input date string also has the matching double M's and double d's: "04/06/2018". ? SCJP 5, OCPJP 7, 8, SCJD 5, SCWCD 4, SCBCD 5, SCJWS 4, IBM OOAD 833 & 834, MongoDB Developer ·
🌐
HowToDoInJava
howtodoinjava.com › home › java 8 › parse a string to date in java 8
Parse a String to Date in Java 8
February 7, 2023 - If you have dates in some custom format, then you need to put additional logic to handle formatting as well using DateTimeFormatter.ofPattern(). String anotherDate = "04 Apr 2016"; DateTimeFormatter df = DateTimeFormatter.ofPattern("dd MMM yyyy"); LocalDate random = LocalDate.parse(anotherDate, df); System.out.println(anotherDate + " parses as " + random); Happy Learning !! ... A fun-loving family man, passionate about computers and problem-solving, with over 15 years of experience in Java and related technologies.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-program-to-convert-string-to-date
Java Program to Convert String to Date - GeeksforGeeks
July 11, 2025 - Convert the String to Date using the Instant.parse() method. If converted successfully, then print the Date. If not converted successfully, then DateTimeParseException is thrown. ... // Java Program to Convert String to Date // Using Instant ...
🌐
Java67
java67.com › 2018 › 01 › how-to-change-date-format-of-string-in-java8.html
How to Format Date to String in Java 8 [Example Tutorial] | Java67
In the first step, you need to parse String to create an equivalent date using the current format, and then once you got the date, you need to again convert it back to String using the new format. The same process is repeated in both Java 8 and before, only corresponding API and class changes.
🌐
Java67
java67.com › 2016 › 04 › how-to-convert-string-to-localdatetime-in-java8-example.html
How to Convert String to LocalDateTime in Java 8 - Example Tutorial | Java67
In Java 8 and beyond, you can use the DateTimeFormatter class to convert String to LocalDate, LocalTime, or LocalDateTime class of Java 8 Date Time API, which represents date, time, and date-time data types.
🌐
Mkyong
mkyong.com › home › java › java – how to change date format in a string
Java - How to change date format in a String - Mkyong.com
May 12, 2019 - package com.mkyong; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class SimpleDateFormatExample { private static final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S"); private static final SimpleDateFormat sdfNew = new SimpleDateFormat("EEEE, MMM d, yyyy HH:mm:ss a"); public static void main(String[] args) { String dateString = "2019-05-23 00:00:00.0"; try { // string to date Date date = sdf.parse(dateString); System.out.println(sdf.format(date)); System.out.println(sdfNew.format(date)); } catch (ParseException e) { e.printStackTrace(); } } }
🌐
Attacomsian
attacomsian.com › blog › java-convert-string-to-date
How to convert a string to date in Java
October 14, 2022 - Java 8 introduced a new date and time API (classes in the java.time.* package) to make it easy to work with dates in Java. These classes use ISO-8601 format to represent dates and times. The new API provides the parse() method that accepts a sequence of characters as an argument and uses the ISO_LOCAL_DATE format to parse the string into a date:
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › how-to-convert-date-to-string-in-java
How to convert Date to String in Java - GeeksforGeeks
Create an instance of SimpleDateFormat class to format the string representation of the date object. Get the date using the Calendar object. Convert the given date into a string using format() method.
Published   July 15, 2025
🌐
Mkyong
mkyong.com › home › java › how to convert string to date – java
How to convert String to Date - Java - Mkyong.com
March 10, 2017 - How should I convert date string from http header to java.util.Date? I am using DateTimeFormatter.RFC_1123_DATE_TIME. ... Concise and clear. Thanks! ... How to I get 07/26/2016 to MM/dd/YYY formate like all formates. ... Try this SimpleDateFormat JavaDoc http://docs.oracle.com/javase/8/docs/api/java/text/SimpleDateFormat.html
Top answer
1 of 16
1853

That's the hard way, and those java.util.Date setter methods have been deprecated since Java 1.1 (1997). Moreover, the whole java.util.Date class was de-facto deprecated (discommended) since introduction of java.time API in Java 8 (2014).

Simply format the date using DateTimeFormatter with a pattern matching the input string (the tutorial is available here).

In your specific case of "January 2, 2010" as the input string:

  1. "January" is the full text month, so use the MMMM pattern for it
  2. "2" is the short day-of-month, so use the d pattern for it.
  3. "2010" is the 4-digit year, so use the yyyy pattern for it.
String string = "January 2, 2010";
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("MMMM d, yyyy", Locale.ENGLISH);
LocalDate date = LocalDate.parse(string, formatter);
System.out.println(date); // 2010-01-02

Note: if your format pattern happens to contain the time part as well, then use LocalDateTime#parse(text, formatter) instead of LocalDate#parse(text, formatter). And, if your format pattern happens to contain the time zone as well, then use ZonedDateTime#parse(text, formatter) instead.

Here's an extract of relevance from the javadoc, listing all available format patterns:

Symbol Meaning Presentation Examples
G era text AD; Anno Domini; A
u year year 2004; 04
y year-of-era year 2004; 04
D day-of-year number 189
M/L month-of-year number/text 7; 07; Jul; July; J
d day-of-month number 10
Q/q quarter-of-year number/text 3; 03; Q3; 3rd quarter
Y week-based-year year 1996; 96
w week-of-week-based-year number 27
W week-of-month number 4
E day-of-week text Tue; Tuesday; T
e/c localized day-of-week number/text 2; 02; Tue; Tuesday; T
F week-of-month number 3
a am-pm-of-day text PM
h clock-hour-of-am-pm (1-12) number 12
K hour-of-am-pm (0-11) number 0
k clock-hour-of-am-pm (1-24) number 0
H hour-of-day (0-23) number 0
m minute-of-hour number 30
s second-of-minute number 55
S fraction-of-second fraction 978
A milli-of-day number 1234
n nano-of-second number 987654321
N nano-of-day number 1234000000
V time-zone ID zone-id America/Los_Angeles; Z; -08:30
z time-zone name zone-name Pacific Standard Time; PST
O localized zone-offset offset-O GMT+8; GMT+08:00; UTC-08:00;
X zone-offset 'Z' for zero offset-X Z; -08; -0830; -08:30; -083015; -08:30:15;
x zone-offset offset-x +0000; -08; -0830; -08:30; -083015; -08:30:15;
Z zone-offset offset-Z +0000; -0800; -08:00;

Do note that it has several predefined formatters for the more popular patterns. So instead of e.g. DateTimeFormatter.ofPattern("EEE, d MMM yyyy HH:mm:ss Z", Locale.ENGLISH);, you could use DateTimeFormatter.RFC_1123_DATE_TIME. This is possible because they are, on the contrary to SimpleDateFormat, thread safe. You could thus also define your own, if necessary.

For a particular input string format, you don't need to use an explicit DateTimeFormatter: a standard ISO 8601 date, like 2016-09-26T17:44:57Z, can be parsed directly with LocalDateTime#parse(text) as it already uses the ISO_LOCAL_DATE_TIME formatter. Similarly, LocalDate#parse(text) parses an ISO date without the time component (see ISO_LOCAL_DATE), and ZonedDateTime#parse(text) parses an ISO date with an offset and time zone added (see ISO_ZONED_DATE_TIME).


Pre-Java 8

In case you're not on Java 8 yet, or are forced to use java.util.Date, then format the date using SimpleDateFormat using a format pattern matching the input string.

String string = "January 2, 2010";
DateFormat format = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH);
Date date = format.parse(string);
System.out.println(date); // Sat Jan 02 00:00:00 GMT 2010

Note the importance of the explicit Locale argument. If you omit it, then it will use the default locale which is not necessarily English as used in the month name of the input string. If the locale doesn't match with the input string, then you would confusingly get a java.text.ParseException even though when the format pattern seems valid.

Here's an extract of relevance from the javadoc, listing all available format patterns:

Letter Date or Time Component Presentation Examples
G Era designator Text AD
y Year Year 1996; 96
Y Week year Year 2009; 09
M/L Month in year Month July; Jul; 07
w Week in year Number 27
W Week in month Number 2
D Day in year Number 189
d Day in month Number 10
F Day of week in month Number 2
E Day in week Text Tuesday; Tue
u Day number of week Number 1
a Am/pm marker Text PM
H Hour in day (0-23) Number 0
k Hour in day (1-24) Number 24
K Hour in am/pm (0-11) Number 0
h Hour in am/pm (1-12) Number 12
m Minute in hour Number 30
s Second in minute Number 55
S Millisecond Number 978
z Time zone General time zone Pacific Standard Time; PST; GMT-08:00
Z Time zone RFC 822 time zone -0800
X Time zone ISO 8601 time zone -08; -0800; -08:00

Note that the patterns are case sensitive and that text based patterns of four characters or more represent the full form; otherwise a short or abbreviated form is used if available. So e.g. MMMMM or more is unnecessary.

Here are some examples of valid SimpleDateFormat patterns to parse a given string to date:

Input string Pattern
2001.07.04 AD at 12:08:56 PDT yyyy.MM.dd G 'at' HH:mm:ss z
Wed, Jul 4, '01 EEE, MMM d, ''yy
12:08 PM h:mm a
12 o'clock PM, Pacific Daylight Time hh 'o''clock' a, zzzz
0:08 PM, PDT K:mm a, z
02001.July.04 AD 12:08 PM yyyyy.MMMM.dd GGG hh:mm aaa
Wed, 4 Jul 2001 12:08:56 -0700 EEE, d MMM yyyy HH:mm:ss Z
010704120856-0700 yyMMddHHmmssZ
2001-07-04T12:08:56.235-0700 yyyy-MM-dd'T'HH:mm:ss.SSSZ
2001-07-04T12:08:56.235-07:00 yyyy-MM-dd'T'HH:mm:ss.SSSXXX
2001-W27-3 YYYY-'W'ww-u

An important note is that SimpleDateFormat is not thread safe. In other words, you should never declare and assign it as a static or instance variable and then reuse it from different methods/threads. You should always create it brand new within the method local scope.

2 of 16
85

Ah yes the Java Date discussion, again. To deal with date manipulation we use Date, Calendar, GregorianCalendar, and SimpleDateFormat. For example using your January date as input:

Calendar mydate = new GregorianCalendar();
String mystring = "January 2, 2010";
Date thedate = new SimpleDateFormat("MMMM d, yyyy", Locale.ENGLISH).parse(mystring);
mydate.setTime(thedate);
//breakdown
System.out.println("mydate -> "+mydate);
System.out.println("year   -> "+mydate.get(Calendar.YEAR));
System.out.println("month  -> "+mydate.get(Calendar.MONTH));
System.out.println("dom    -> "+mydate.get(Calendar.DAY_OF_MONTH));
System.out.println("dow    -> "+mydate.get(Calendar.DAY_OF_WEEK));
System.out.println("hour   -> "+mydate.get(Calendar.HOUR));
System.out.println("minute -> "+mydate.get(Calendar.MINUTE));
System.out.println("second -> "+mydate.get(Calendar.SECOND));
System.out.println("milli  -> "+mydate.get(Calendar.MILLISECOND));
System.out.println("ampm   -> "+mydate.get(Calendar.AM_PM));
System.out.println("hod    -> "+mydate.get(Calendar.HOUR_OF_DAY));

Then you can manipulate that with something like:

Calendar now = Calendar.getInstance();
mydate.set(Calendar.YEAR,2009);
mydate.set(Calendar.MONTH,Calendar.FEBRUARY);
mydate.set(Calendar.DAY_OF_MONTH,25);
mydate.set(Calendar.HOUR_OF_DAY,now.get(Calendar.HOUR_OF_DAY));
mydate.set(Calendar.MINUTE,now.get(Calendar.MINUTE));
mydate.set(Calendar.SECOND,now.get(Calendar.SECOND));
// or with one statement
//mydate.set(2009, Calendar.FEBRUARY, 25, now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
System.out.println("mydate -> "+mydate);
System.out.println("year   -> "+mydate.get(Calendar.YEAR));
System.out.println("month  -> "+mydate.get(Calendar.MONTH));
System.out.println("dom    -> "+mydate.get(Calendar.DAY_OF_MONTH));
System.out.println("dow    -> "+mydate.get(Calendar.DAY_OF_WEEK));
System.out.println("hour   -> "+mydate.get(Calendar.HOUR));
System.out.println("minute -> "+mydate.get(Calendar.MINUTE));
System.out.println("second -> "+mydate.get(Calendar.SECOND));
System.out.println("milli  -> "+mydate.get(Calendar.MILLISECOND));
System.out.println("ampm   -> "+mydate.get(Calendar.AM_PM));
System.out.println("hod    -> "+mydate.get(Calendar.HOUR_OF_DAY));
🌐
Java Code Geeks
javacodegeeks.com › home › core java
How to format/parse dates with LocalDateTime in Java 8 - Example Tutorial - Java Code Geeks
August 9, 2017 - Once you got your formatter, parsing or formatting date is as easy as calling a method. You just need to call the LocalDateTime.parse() method to convert a String to LocalDateTime in Java 8.
🌐
Coderanch
coderanch.com › t › 686925 › java › Convert-string-date
Convert string to date (Beginning Java forum at Coderanch)
I am sorry, I missed read that ... Java 8 Date Time API: ... Stop using the Date class. Wayan Saryada is right. Use LocalDate or similar; see the Java™ Tutorials. Since Java8 came out over 3½ years ago, you most probably can use LocalDate. I think you have managed to find the wrong forum and this discussion would fit better in a more general forum, so I shall move you. ... Short answer. Don't feed a date string that's ...
🌐
Mkyong
mkyong.com › home › java8 › java 8 – how to convert string to localdate
Java 8 - How to convert String to LocalDate - Mkyong.com
February 4, 2020 - DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d/MM/yyyy"); String date = "16/08/2016"; //convert String to LocalDate LocalDate localDate = LocalDate.parse(date, formatter); The key is understand the DateTimeFormatter patterns · Note You may interest at this classic java.util.Date example – How to convert String to Date in Java
🌐
Sentry
sentry.io › sentry answers › java › how do i convert a string to a date in java?
How Do I Convert a String to a Date in Java? | Sentry
The recommended way to convert a String to a Date in Java is to use the DateTimeFormatter class from java.time. The DateTimeFormatter class is thread-safe, making it a better choice for multithreaded environments.