gpt4 book ai didi

c - Arduino UDPNTP Epoch,确定一天中的分钟

转载 作者:太空宇宙 更新时间:2023-11-04 04:37:46 25 4
gpt4 key购买 nike

我在弄清楚这个问题时遇到了一些麻烦。

每天有 1440 分钟。我想使用 NTP 确定当天的当前分钟,所以 12:00pm 将是 720,12:01pm 将是 721 等等

我正在使用 C 在 arduino 开发板上执行此操作,

const unsigned long seventyYears = 2208988800UL;     
unsigned long epoch = secsSince1900 - seventyYears;

我知道 (epoch % 3600 )/60 给我当前小时的当前分钟(尽管它不是 100% 清楚如何)。


更新

下面的答案是正确的,但我的结果没有意义:

Serial.print("Unix time = ");
const unsigned long seventyYears = 2208988800UL;
unsigned long epoch = secsSince1900 - seventyYears;
Serial.println(epoch);
Serial.println((epoch % (3600 * 24))/ 60);


[Output:]
Unix time = 1427815654
144

但是当我计算 (1427815654 % (3600 * 24))/60 时,我得到 927,这正是我所期望的。我的板子是怎么从哪里得到 144 的?

最佳答案

如果 (epoch % 3600 )/60 对你来说足够精确,你可以简单地使用:

(epoch % (3600 * 24)) / 60 

(但是忽略了闰秒)


解释

% 给出除法的剩余部分。

因此我们将自纪元以来的所有秒数除以一天中的秒数 (3600 * 24)。我们现在是一天中的第二天,因此除以 60 就是分钟。

关于c - Arduino UDPNTP Epoch,确定一天中的分钟,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29371156/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com