【问题标题】:Setting a time in Luxon and showing it in the user's local timezone在 Luxon 中设置时间并以用户的本地时区显示
【发布时间】:2021-02-09 04:46:03
【问题描述】:

我正在使用 Luxon 来显示何时处理订单。如果他们在美国东部标准时间上午 9 点到下午 5 点的营业时间之后下订单,我想告诉他们他们的订单将在美国东部标准时间的第二天下午 2:00 准备好。

    let easternTime = luxon.DateTime.local().setZone('America/New_York');
    let localTime = luxon.DateTime.local();
    // Omitted/Irrelevant Logic to determine if time is after 9am-5pm EST

    console.log("Business closed...turnaround next day");
    console.log(easternTime.toLocal().plus({ day: 1 }).toFormat('EEE, MMM d, 2:00 a ZZZZ'));

如果有人在旧金山 (PST) 看到这条消息,我希望有时间阅读太平洋标准时间上午 11:00。我将如何使用 Luxon 或其他框架来完成此任务?

谢谢!

【问题讨论】:

    标签: timezone luxon


    【解决方案1】:

    只需要使用 .set({ hour: 14 }) 功能:

    console.log(easternTime.set({ hour: 14 }).set({ minutes: 0 }).toLocal().plus({ day: 1 }).toFormat('EEE, MMM d, h:mm a ZZZZ'));
    

    【讨论】:

      猜你喜欢
      • 2015-07-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-01-04
      • 1970-01-01
      • 2021-07-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多