0 votes
849 views
in Java by
How to convert date to string in java?. Anybody can give suitable example.

1 Answer

0 votes
by
With the help of following code you can easly convert date to string.
 
package com;
 
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 
 
public class DateToString {
 
/**
* @param args
*/
public static void main(String[] args) {
DateFormat sdf = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
Calendar cal = Calendar.getInstance();
Date currDate = cal.getTime();
String strDate = sdf.format(currDate);
System.out.println("Current Date: " + currDate + ", String Date: " + strDate);
}
 
}
 
Output:
Current Date: Mon Sep 23 16:48:43 IST 2013, String Date: 09/23/2013 16:48:43

Share:- Whatsapp Facebook Facebook


Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

Categories

...