因为经常会不经意的会使用获取某个时间去做定时任务等等,故此记录以下
# Timestamp of the specified time
def get_timestamp_spec_time(clock, days=0):
"""
获取指定的时间点的时间戳
:param clock: 钟点;指定的时间,比如当天的凌晨一点,钟点即为1(24小时制)
:param days: 与当前时间的相差的日期。-1 表示昨天;0 表示当天(默认);1 表示明天
:return: 返回时间戳
"""
nowTime = datetime.datetime.now() + datetime.timedelta(days=days)
specified_time = nowTime.strftime("%Y-%m-%d") + " {}:00:00".format(clock)
timeArray = time.strptime(specified_time, "%Y-%m-%d %H:%M:%S")
return time.mktime(timeArray)