使用unix epoch时间戳的操作

Operations with unix epoch timestamp

本文关键字:操作 时间戳 epoch unix 使用      更新时间:2023-10-27

我需要帮助,问题是我需要知道如何将unix epoch时间戳格式的一个日期(a)与jquery中的实际日期(b)进行比较,我需要知道(a)它是否与实际日期间隔3小时(b)

您可以检查unix时间戳(从epoch算起的秒数)是否在另一个日期的3h内(otherDateB是日期对象,epochTimeStampA是数字形式的epoch时间戳):

function withinThreeHours(epochTimeStampA, otherDateB) {
    var aTimeFromBtime = otherDateB - (epochTimeStampA * 1000);
    var threeHours = 1000 * 60 * 60 * 3;
    return aTimeFromBtime <= threeHours;
}