根据剩余时间更改班级

时间:2019-05-20 13:58:44

标签: javascript

如何根据直到0小时(当前为下午2点)的X时间更改班级

例如,我想在5小时到下午2点之间的时间更改班级。 (start.setHours(14, 0, 0); // 2pm

(function() {
  var start = new Date;
  start.setHours(14, 0, 0); // 2pm

  function pad(num) {
    return ("0" + parseInt(num)).substr(-2);
  }

  function tick() {
    var now = new Date;
    if (now > start) { // too late, go to tomorrow
      start.setDate(start.getDate() + 1);
    }
    var remain = ((start - now) / 1000);
    var hh = pad((remain / 60 / 60) % 60);
    var mm = pad((remain / 60) % 60);
    var ss = pad(remain % 60);
    document.getElementById('time').innerHTML =
      hh + "hrs " + mm + "mins " + ss + "secs ";
    setTimeout(tick, 1000);
  }

  document.addEventListener('DOMContentLoaded', tick);
})();
<span id="time"></span>

1 个答案:

答案 0 :(得分:0)

像这样吗?

SELECT DISTINCT
FIRST_VALUE()
with data as (
  select * from (
  VALUES (1, 'Blue pill'),
         (2, 'Red pill'),
         (3, 'Blue shift'),
         (4, 'Red eye')
  ) v(id, t)
)
select id, lexeme, positions
FROM data
CROSS JOIN unnest(to_tsvector(t)) u(lexeme, positions, weights)
WHERE (lexeme = 'red' and positions @> '{1}')
OR (lexeme = 'pill' and positions @> '{2}');
 id | lexeme | positions
----+--------+-----------
  1 | pill   | {2}
  2 | pill   | {2}
  2 | red    | {1}
  4 | red    | {1}
(4 rows)