Tuesday, 4 April 2017

Convert Date Object into String Object



Sometimes we have a requirement where we need to convert the date object received from input into String object.

Sample Program:


 import java.text.DateFormat;  
 import java.text.SimpleDateFormat;  
 import java.util.Date;  
 public class ConvertDateToStringExample {  
      public static void main(String[] args) {  
           Date date=new Date();  
           DateFormat dateFormatter=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");  
           String strDate=dateFormatter.format(date);  
           System.out.println("Converted Date:" +strDate);  
      }  
 }  

Output:


Converted Date:2017-04-04 08:57:44  


Enjoy Coding.

No comments:

Post a Comment