-
Notifications
You must be signed in to change notification settings - Fork 461
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #364 from chinmay7016/patch-1
Create Alaram-clock
- Loading branch information
Showing
1 changed file
with
25 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 | ||
} | ||
} | ||
}; |