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);
}
}

Related Post

Converting String to Date object
Validating date in Java Script
The Constructor Date(String) is Deprecated since of JDK 1.1 you should not use it
String.intern in Java
String in Java?

Comments

Leave a Reply




Technology