Convert Date To String Java Program

In this post we are going to learn convert date to string java program.

In the below example or program SimpleDateFormat class is used.

Here i have used “yyyy-mm-dd hh:mm:ss” format to show converted date.

Example: Convert Date To String Java Program

Convert Date To String Java Program

Also Read – Convert Binary Number To Decimal Number in Java

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

public class Date_to_String {

public static void main(String[] args) {

Date dt = new Date();

DateFormat df = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");

String str_Date = df.format(dt);

System.out.println("Converted Date to String: " + str_Date);

}
}

Output:

Converted Date to String: 2015-05-05 10:10:10

About the author

admin

View all posts

Leave a Reply

Your email address will not be published. Required fields are marked *