File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed
Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 1+ // Java program to convert 24 hour
2+ // time format to 12 hour format
3+
4+ // Importing specific date class libraries
5+ import java .util .Date ;
6+ import java .text .SimpleDateFormat ;
7+
8+ public class GFG {
9+
10+ // Main driver method
11+ public static void main (String [] args )
12+ {
13+ // Getting the current current time
14+ Date date = new Date ();
15+
16+
17+ System .out .println ("Current Time is : " + date );
18+
19+ // set format in 12 hours
20+ SimpleDateFormat formatTime = new SimpleDateFormat ("hh.mm aa" );
21+ // hh = hours in 12hr format
22+ // mm = minutes
23+ // aa = am/pm
24+
25+ String time = formatTime .format (
26+ date ); // changing the format of 'date'
27+
28+ // display time as per format
29+ System .out .println (
30+ "Current Time in AM/PM Format is : " + time );
31+ }
32+ }
You can’t perform that action at this time.
0 commit comments