A java program to get current date time using the java.util.Calendar class. Check the blog post at https://coderolls.com/get-current-date-time-in-java/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.text.SimpleDateFormat; | |
import java.util.Calendar; | |
import java.util.Date; | |
/** | |
* A java program to get current date time using the java.util.Calendar class | |
* @author Gaurav Kukade at coderolls.com | |
*/ | |
public class CalendarExample { | |
public static void main(String[] args) { | |
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); | |
// get the instance of the java.util.Calendar | |
Calendar calendar = Calendar.getInstance(); | |
// getTime() method returns the instance of java.util.Date | |
Date date = calendar.getTime(); | |
// prints the date object | |
System.out.println(date); // Sat May 15 12:50:17 IST 2021 | |
// print the formated date | |
System.out.println(simpleDateFormat.format(date)); // 15/05/2021 12:50:17 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment