Python中的AlarmTime模块介绍
闹钟时间是Python中的一个Python模块,用于玩弄日期和时间,使用Python默认的datetime模块。 Python中的日期不是它自己的数据类型,但我们可以导入一个名为datetime的模块来将日期作为日期对象处理。它具有以天或小时或秒为单位查找日期之间差异的功能。该模块能够从字符串文本中找到日期,例如以字符串格式提及接下来 10 天的日期。
安装:
pip install AlarmTime
方法(主要功能):
DateTimeDetect : It detects the date from the string
hour_diff_from_now : It gives difference between dates in hours
millisecond_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
示例 1:
在这个例子中,我们将创建一个检测日期对象来打印日期
Python3
# import the detectdate class from alarmtime 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)
Python3
# import the detectdate class from alarmtime 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 seconds 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))
输出 :
示例 2:
在这里,我们将使用DetectDate对象的各种主要功能。
蟒蛇3
# import the detectdate class from alarmtime 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 seconds 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))
输出 :