Use SimpleDateFormat
(a good tutorial is available here). Consider this example:
Date date = new Date();
System.out.println(date);
which outputs:
Mon Jun 24 21:46:22 BST 2013
To convert to EDM format, do the following:
String firstPartOfPattern = "yyyy-MM-dd";
String secondPartOfPattern = "HH:mm:ss";
SimpleDateFormat sdf1 = new SimpleDateFormat(firstPartOfPattern);
SimpleDateFormat sdf2 = new SimpleDateFormat(secondPartOfPattern);
String formattedDate = sdf1.format(date) + "T" + sdf2.format(date);
formattedDate
now has the following format:
2013-06-24T21:46:22