Related Article: Get current date and time. But this article guides you to fetch current date and time in different formats. Just define your SimpleDateFormat object with desired format and format the current date and time by using format() method.
Calendar c = Calendar.getInstance(); System.out.println("Current time => " + c.getTime()); SimpleDateFormat df1 = new SimpleDateFormat("dd-MMM-yyyy"); String formattedDate1 = df1.format(c.getTime()); SimpleDateFormat df2 = new SimpleDateFormat("dd-MM-yyyy"); String formattedDate2 = df2.format(c.getTime()); SimpleDateFormat df3 = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss a"); String formattedDate3 = df3.format(c.getTime()); System.out.println("=========> Date 1 => "+formattedDate1); System.out.println("=========> Date 2 => "+formattedDate2); System.out.println("=========> Date 3 => "+formattedDate3);