在小脚本中将当前时间获取为变量时遇到问题。

huangapple go评论38阅读模式
英文:

Having trouble getting current time as a variable in the little script

问题

尝试动态获取此脚本的 "now" 字段的时间。我尝试使用 $.now() 和 Date(),但似乎找不到正确的组合。PS... 我对 JQuery 不熟悉,因为我是新手,所以才来这里。

倒计时有效... 但每次刷新页面时都从列出的时间戳 "now" 开始。此处的变量被提供给我没有编写的主要脚本。

$('.countdown').final_countdown({
  start: 1686226400,
  end: 1696226400,
  now: 1686226400,
  seconds: {
    borderColor: '#5677fc',
    borderWidth: '3'
  },
  minutes: {
    borderColor: '#7e57c2',
    borderWidth: '3'
  },
  hours: {
    borderColor: '#4db6ac',
    borderWidth: '3'
  },
  days: {
    borderColor: '#d81b60',
    borderWidth: '3'
  }
}, function() {});

任何帮助都将不胜感激。

尝试设置变量 now = $.now()... 但似乎对我不起作用。

英文:

Trying to get time dynamically for the now field of this script. I have tried using $.now() and Date() but can't seem to find the right combination. PS... I suck at JQuery as I am a newb so this is why I am here

The countdown works... but always starts at the time stamp listed as now every time the page is refreshed. The variable here is fed to primary script which I did not write.

<!-- begin snippet: js hide: false console: true babel: false -->

<!-- language: lang-js -->

$(&#39;.countdown&#39;).final_countdown({
  start: 1686226400,
  end: 1696226400,
  now: 1686226400,
  seconds: {
    borderColor: &#39;#5677fc&#39;,
    borderWidth: &#39;3&#39;
  },
  minutes: {
    borderColor: &#39;#7e57c2&#39;,
    borderWidth: &#39;3&#39;
  },
  hours: {
    borderColor: &#39;#4db6ac&#39;,
    borderWidth: &#39;3&#39;
  },
  days: {
    borderColor: &#39;#d81b60&#39;,
    borderWidth: &#39;3&#39;
  }
}, function() {});

<!-- end snippet -->

Any help would be appreciated.

Tried setting var now = $.now()... but did not seem to work for me

答案1

得分: -1

将输出从毫秒转换为秒。尝试:

现在:Math.floor($.now() / 1000),
英文:

You need to convert the output from milliseconds to seconds. Try:

now: Math.floor($.now() / 1000),

huangapple
  • 本文由 发表于 2023年6月13日 14:18:49
  • 转载请务必保留本文链接:https://go.coder-hub.com/76462134.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定