We would like to know how to strip Date from Calendar.
import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; /*from ww w . j a v a 2 s . c o m*/ public class Main { public static void main(String[] args) { Calendar cal = Calendar.getInstance(); System.out.println("Calendar:" + cal.toString()); Date d = cal.getTime(); SimpleDateFormat sdf = new SimpleDateFormat("DD/MM/yyyy HH:mm:ss"); System.out.println(sdf.format(d)); SimpleDateFormat sdfNew = new SimpleDateFormat("HH:mm:ss"); System.out.println(sdfNew.format(d)); } }
The code above generates the following result.