How to get time difference between two timestamps in seconds with jQuery?

前端 未结 5 573
猫巷女王i
猫巷女王i 2020-12-15 08:16

I want to display x seconds ago based on a MySQL Timestamp.

I found the plugin called timeago

But I cannot find a way to make it display only se

5条回答
  •  臣服心动
    2020-12-15 08:18

    If you are okay with that plugin you can modify it a little bit to work with seconds only

      var words = seconds < 45 && substitute($l.seconds, Math.round(seconds)) ||
        seconds < 90 && substitute($l.minute, 1) ||
        minutes < 45 && substitute($l.minutes, Math.round(minutes)) ||
        minutes < 90 && substitute($l.hour, 1) ||
        hours < 24 && substitute($l.hours, Math.round(hours)) ||
        hours < 42 && substitute($l.day, 1) ||
        days < 30 && substitute($l.days, Math.round(days)) ||
        days < 45 && substitute($l.month, 1) ||
        days < 365 && substitute($l.months, Math.round(days / 30)) ||
        years < 1.5 && substitute($l.year, 1) ||
        substitute($l.years, Math.round(years));
    

    with this part, go only with converting to seconds

    see the fiddle: http://jsfiddle.net/zGXLU/1/

提交回复
热议问题