Java Date To String

Hey guys!! How are you doing?? Welcome to flower brackets blog. In this post we are going to learn java date to string.

java date to string

Types of date formats in java :

Date FormatExample
dd-MM-yyyy HH:mm:ss05/06/05 14:10:05
MM dd, yyyy05 06, 2005
E, MMM dd yyyySat, Jun 05 2005
E, MMM dd yyyy HH:mm:ssSat, Jun 05 2005 18:20:08

In the below java program to convert date to string, format() method of SimpleDateFormat class is used.

Also Read – how to convert string to date in java

Here I’m using different date formats for converting it to string,


import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class DateToString
   public static void main(String[] args)
      DateFormat format1 = new SimpleDateFormat("dd/MM/yyyy");
      DateFormat format2 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
      DateFormat format3 = new SimpleDateFormat("dd-MMM-yyyy");
      DateFormat format4 = new SimpleDateFormat("MM dd, yyyy");
      DateFormat format5 = new SimpleDateFormat("E, MMM dd yyyy");
      DateFormat format6 = new SimpleDateFormat("E, MMM dd yyyy HH:mm:ss");
      DateFormat format7 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
      Date systemDate = new Date();
         System.out.println("Java date conversion");
         String checkDate = format1.format(systemDate);           
         System.out.println("dd/MM/yyyy format is : " + checkDate);
         String str2 = format2.format(systemDate);          
         System.out.println("dd-MM-yyyy HH:mm:ss format is : " + str2);
         String str3 = format3.format(systemDate);          
         System.out.println("dd-MMM-yyyy format is : " + str3);
         String str4 = format4.format(systemDate);
         System.out.println("MM dd, yyyy format is : " + str4);
         String str5 = format5.format(systemDate);
         System.out.println("E, MMM dd yyyy format is : " + str5);
         String str6 = format6.format(systemDate);
         System.out.println("E, MMM dd yyyy HH:mm:ss format is : " + str6);
         String str7 = format7.format(systemDate);
	 System.out.println("yyyy-mm-dd hh:mm:ss format is : " + str7);
      catch (Exception ex)


Java date conversion
dd/MM/yyyy format is : 16/08/2018
dd-MM-yyyy HH:mm:ss format is : 16-08-2018 13:14:16
dd-MMM-yyyy format is : 16-Aug-2018
MM dd, yyyy format is : 08 16, 2018
E, MMM dd yyyy format is : Thu, Aug 16 2018
E, MMM dd yyyy HH:mm:ss format is : Thu, Aug 16 2018 13:14:16
yyyy-mm-dd hh:mm:ss format is : 2016-14-16 01:14:16


That’s it guys. This is all about how to convert date to string in java with example. I hope you have understood the concept.

You can subscribe to my blog flower brackets if you haven’t already.

Do share this post if you like.

Related Posts