Home / Programs / Write a java program to print current date and time in the specified format. Current Date and Time : June 19, 2017 3:13 pm
🚀 Programming Example

Write a java program to print current date and time in the specified format.

Current Date and Time :
June 19, 2017
3:13 pm

👁 789 Views
💻 Practical Program
📘 Step Learning
Java program to print current date and time in the specified format.

💻 Program Code

import java.util.Calendar;

public class Exercise {

 public static void main(String[] args) {
    Calendar c = Calendar.getInstance();
      System.out.println("Current Date and Time :");
      System.out.format("%tB %te, %tY%n", c, c, c);
      System.out.format("%tl:%tM %tp%n", c, c, c);
   }
   }

                        

🖥 Program Output

Current Date and Time :
June 9, 2018
3:51 pm
Press any key to continue . . .
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.