Skip to content
Related Articles

Related Articles

Introduction to AlaramTime Module in Python
  • Last Updated : 24 Oct, 2020

AlaramTime is a python module in python which is used to play with the date and time, using default datetime module of python. A date in Python is not a data type of its own, but we can import a module named datetime to work with dates as date objects. It has functions for finding difference between the dates in days or hours or seconds. This module is able to find the dates from the string text, like mentioning date for next 10 days in string format.

Installation:

pip install AlarmTime

Methods (Major Functions):

DateTimeDetect : It detects the date from the string 
hour_diff_from_now : It gives difference between dates in hours 
milisecond_diff_from_now: It gives difference between dates in milliseconds 
minute_diff_from_now : It gives difference between dates in minutes 
second_diff_from_now : It gives difference between dates in seconds

Example 1: 
In this example, we will create a detectdate object to print the dates 



Python3




# import the detectdate class from alaramtime module
from AlarmTime.AlarmTime import DetectDate
  
# create a detectdate object for current date & time
# by passing parameter as 0 will give current date & time
current = DetectDate(0)
  
# printing the current date&time
# now attribute for date&time
print(current.now)
  
# creating another detectdate object
# passing 1 as argument i.e 1second after default date
another = DetectDate(1)
  
# printing date & time of another variable
print(another.now)
  
# creating another detectdate object
# after 1570010023345 seconds
another2 = DetectDate(1570010023345)
  
# printing date & time
print(another2.now)

Output : 
 

Example 2: 
Here we will use various major functions with the DetectDate object. 

Python3




# import the detectdate class from alaramtime module
from AlarmTime.AlarmTime import DetectDate
  
# creatingdetectdate object
# after 1570010023345 seconds
first_date = DetectDate(1570010023345)
  
# create a detectdate object for current date & time
# by passing parameter as 0 will give current date & time
current = DetectDate(0)
  
# getting two dates difference in seconds
seconds = current.second_diff_from_now("after 10 days")
  
# printing the secodns value
print("Seconds Difference : " + str(seconds))
  
  
# detecting the date & time  using string
target_time = current.DateTimeDetect(
    'detect the time and date on October 10 10 p.m')
  
# printing the detected date
print("Detected date : " + str(target_time))
  
# detecting date after some time
target_time2 = current.DateTimeDetect(
    'after 6 month 500 days 10 hours 15 minutes')
  
# printing the detected date & time
print("Detected date after some time : " + str(target_time2))

Output : 
 

 

 Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.  

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning – Basic Level Course

My Personal Notes arrow_drop_up
Recommended Articles
Page :