将日,小时和分钟转换为UTC - node.js

时间:2017-07-12 09:48:16

标签: node.js datetime timezone

我将从用户那里获得时间输入以安排任务。选项如下,

  • 星期几,小时和分钟(或)
  • 日期,时间和分钟(或)
  • 一年中的某个月,小时和分钟(或)

用户可以在任何时区。我已将我的数据库表建模为将用户输入存储为配置。 在我的表中,我将计算next_run_at并填充它,以便轮询器可以根据它找到要运行的作业并执行。

要与时区无关,我的next_run_at应该是UTC。 有没有办法在UTC中单独转换上述配置(日,小时,分钟)并存储它?

TL; DR 我知道我们可以将日期转换为特定的时区。有没有办法将单日,小时和分钟的组合单独转换为UTC?

2 个答案:

答案 0 :(得分:0)

根据您的日期,时间和分钟构建日期。将其转换为UTC并获取日期,小时和月份值。

但我认为关于这一天对应的月份会有边缘情况。

<nav role='navigation'> </nav> <div class="content"> <div id="left"> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> <p>Scrolling Content</p> </div> <div id="right"> <div id="fixed"> <p>This content should not scroll</p> <p>This content should not scroll</p> <p>This content should not scroll</p> <p>This content should not scroll</p> <p>This content should not scroll</p> <p>This content should not scroll</p> <p>This content should not scroll</p> </div> </div> </div>将为23:00 28th Feb PST;

06:00 1st Mar UTC将为23:00 28th Mar PST

答案 1 :(得分:0)

你问:

  

有没有办法将单日,小时和分钟的组合单独转换为UTC?

不,没有一般的方法可以做到这一点。您必须拥有完整的日期和时间,包括年,月,日,小时和分钟。否则,您无法确定夏令时是否有效,或标准时间是否已更改。

您必须承担一些您不具备的数据。例如,您可以假设数据是相对于&#34;现在&#34;。只需了解您将获得不同的结果,具体取决于您运行代码的时间。

当然,如果相关时区只有一个固定偏移量,例如亚利桑那州固定为UTC-7,则不适用。只是你不能在世界任何时区的一般情况下假设这一点。

相关问题