-
Notifications
You must be signed in to change notification settings - Fork 617
/
Copy pathalaram-clock.java
25 lines (21 loc) · 891 Bytes
/
alaram-clock.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
import java.util.Timer;
import java.util.TimerTask;
import java.text.SimpleDateFormat;
import java.util.Date;
public class AlarmClock {
public static void main(String[] args) {
// Set the alarm time (24-hour format)
String alarmTime = "15:30"; // Change this to your desired alarm time
// Create a timer
Timer timer = new Timer();
// Define a task to be executed when the alarm time is reached
TimerTask task = new TimerTask() {
public void run() {
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
String currentTime = sdf.format(new Date());
if (currentTime.equals(alarmTime)) {
System.out.println("Alarm! It's time to wake up!");
// You can replace the message with any action you want
}
}
};