Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create Alaram-clock #364

Merged
merged 2 commits into from
Oct 21, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions Alaram-clock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
fixes #363
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
}
}
};
Loading