【问题标题】:How to set specific start time in FlipClock js widget?如何在 FlipClock js 小部件中设置特定的开始时间?
【发布时间】:2017-08-31 07:58:30
【问题描述】:

我想在FlipClock.js 小部件中设置纽约时间以及moment.js。我试过了

HTML
<div class="my_flip_clock"></div>

JS
var a = moment.tz('America/New_York');
var clock = $('.my_flip_clock').FlipClock({
    clockFace: 'TwelveHourClock'
});
clock.setTime(new Date(a.format()).getTime() / 1000);

【问题讨论】:

  • 您能否提供您正在使用的 moment.js 和 flipclock.js 的链接?谷歌搜索最有可能的没有带有 tz 方法的 moment.js 或带有 setTime 方法的 flipclock.js。
  • 嗨 @TonyMiller,这里是带有 tz 方法的 moment.js 的链接 - here 和 setTime 方法 here

标签: javascript jquery datetime momentjs flipclock


【解决方案1】:

来自Moment Timezone documentation

在 Moment.js 中使用时区有两个接口。

moment.tz(..., String) 用于创建带有时区的时刻,而 moment().tz(String) 用于更改现有时刻的时区。

var d = new Date(); // Get a new JS Date instance at current time in system time zone
var a = moment.tz(d.getTime(), 'America/New_York');  // Convert to New York time zone
var dny = new Date(a.format('YYYY-MM-DD hh:mm:ss a')); // Get new JS Date instance for values in New York
var clock = $('.my_flip_clock').FlipClock(dny, {
    clockFace: 'TwelveHourClock'
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-16
    • 2012-09-19
    • 1970-01-01
    • 1970-01-01
    • 2019-09-14
    • 1970-01-01
    相关资源
    最近更新 更多