python獲取當前時間距離指定時間相差的秒值


代碼如下:

import time

def interval_time(date):
    """獲取當前時間距離指定時相差的秒值
    :param date: 格式為:"2021-07-28 18:25"
    :return: 返回秒
    """
    now_time = int(time.time())
    # 觸發時間精確到分
    trigger_time = int(time.mktime(time.strptime(date, "%Y-%m-%d %H:%M")))
    if trigger_time > now_time:
        seconds = trigger_time - now_time
        return seconds
    else:
        print("輸入日期小於當前時間")

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM