Converting Date to String object
Below is the code for converting Date to specified String. This code uses SimpleDateFormat class for converting Date to String.
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
public class DateUtils {
public static void main(String[] args) {
DateFormat dateFormat = new SimpleDateFormat("yyyy-dd-mm");
Date now = new Date();
// Convert Date object to date string in the above mentioned format
String strNow = dateFormat.format(now);
System.out.println(strNow);
}
}
August 18, 2008 | Filed Under Java
Related Post
Comments
Leave a Reply