Skip to content

Commit 4486fd8

Browse files
Merge pull request #364 from chinmay7016/patch-1
Create Alaram-clock
2 parents e89d35c + ada20f2 commit 4486fd8

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Alaram_clock.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import java.util.Timer;
2+
import java.util.TimerTask;
3+
import java.text.SimpleDateFormat;
4+
import java.util.Date;
5+
6+
public class AlarmClock {
7+
8+
public static void main(String[] args) {
9+
// Set the alarm time (24-hour format)
10+
String alarmTime = "15:30"; // Change this to your desired alarm time
11+
12+
// Create a timer
13+
Timer timer = new Timer();
14+
15+
// Define a task to be executed when the alarm time is reached
16+
TimerTask task = new TimerTask() {
17+
public void run() {
18+
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
19+
String currentTime = sdf.format(new Date());
20+
if (currentTime.equals(alarmTime)) {
21+
System.out.println("Alarm! It's time to wake up!");
22+
// You can replace the message with any action you want
23+
}
24+
}
25+
};

0 commit comments

Comments
 (0)