forked from Annex5061/java-algorithms
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Date_and_time.java
32 lines (24 loc) · 722 Bytes
/
Date_and_time.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
// Java program to convert 24 hour
// time format to 12 hour format
// Importing specific date class libraries
import java.util.Date;
import java.text.SimpleDateFormat;
public class GFG {
// Main driver method
public static void main(String[] args)
{
// Getting the current current time
Date date = new Date();
System.out.println("Current Time is : " + date);
// set format in 12 hours
SimpleDateFormat formatTime = new SimpleDateFormat("hh.mm aa");
// hh = hours in 12hr format
// mm = minutes
// aa = am/pm
String time = formatTime.format(
date); // changing the format of 'date'
// display time as per format
System.out.println(
"Current Time in AM/PM Format is : " + time);
}
}