w3resource
Java Programming Exercies

Java String Exercises: Print current date and time in the specified format

Java String : Exercise-15 with Solution

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

Pictorial Presentation:

Java String Exercises: Print current date and time in the specified format

Sample Solution:

Java Code:

import java.util.Calendar;

public class Exercise15 {
 
 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); 
   }
   }

Sample Output:

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

N.B. : The current date and time will change according to your system date and time.

Flowchart:

Flowchart: Java String  Exercises - Print current date and time in the specified format

Java Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a Java program to compare a given string to another string, ignoring case considerations.
Next: Write a Java program to get the contents of a given string as a byte array.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming