Skip to content

Commit ee573bb

Browse files
authored
Date_and_time
1 parent e098222 commit ee573bb

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

Date_and_time.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
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+
}

0 commit comments

Comments
 (0)