Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from datetime import datetime
- import time
- def show_current_time():
- now = datetime.now()
- print("Current Date and Time:",now.strftime("%Y-%m-%d %H:%M:%S"))
- def set_alarm(hour,minute):
- print(f"Alarm set for {hour}:{minute}. Waiting to ring...")
- while True:
- now = datetime.now()
- if now.hour == hour and now.minute == minute:
- print("It is time to wake up!!")
- print("📢📢📢📢📢📢📢📢📢")
- break
- time.sleep(10)
- def calc_date_diff(date1,date2):
- d1 = datetime.strptime(date1,"%Y-%m-%d")
- d2 = datetime.strptime(date2,"%Y-%m-%d")
- diff = abs((d2-d1).days)
- print(f"The difference between {date1} and {date2} is {diff} days.")
- print("Date and Time Application")
- while True:
- print("1. Show Current Date & Time")
- print("2. Set an Alarm")
- print("3. Calculate Date Difference")
- print("4. Exit")
- choice = input("Enter your choice:")
- if (choice=='1'):
- show_current_time()
- elif (choice=='2'):
- hour = int(input("Enter hour (24-hour format):"))
- minute = int(input("Enter minute:"))
- set_alarm(hour,minute)
- elif (choice=='3'):
- date1 = input("Enter 1st date (YYYY-MM-DD):")
- date2 = input("Enter 2nd date (YYYY-MM-DD):")
- calc_date_diff(date1,date2)
- elif (choice=='4'):
- print("Exiting")
- break
- else:
- print("Invalid choice. Please try again.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement