Format java.util.Date with yyyy-MM-dd'T'HH:mm:ss in Java
Description
The following code shows how to format java.util.Date with yyyy-MM-dd'T'HH:mm:ss.
Example
//from www . j ava2 s . co m
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
public class Main {
public static String getStringFromDate (Date date) throws ParseException {
DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
return formatter.format(date);
}
public static void main(String[] argv) throws ParseException {
System.out.println(getStringFromDate(new Date()));
}
}
The code above generates the following result.