伪代码算法从给定的日期和时间开始计算UNIX Epoch时间戳?

发布于 2025-01-31 04:29:21 字数 437 浏览 2 评论 0原文

给定的UTC日期和时间为dayhour,分钟 ,第二,我想知道一个伪代码算法来计算相应的Unix Epoch时间戳。

一分钟内有60秒,一个小时内60分钟,一天24小时。因此,我们每天只能使用60×60×24 = 86400秒,然后倒数直到1970-01-01t00:00:00:00z,对吗?但是,几个月的天数不同。因此,最好跳过并每年使用365天。但是,有了leap年...和leap秒...等等?

这是否突然使该算法像处理 timezones 是或它是它仍然很容易描述吗?

Given UTC date and time as year, month, day, hour, minute, second, I was wondering about a pseudo-code algorithm to calculate the corresponding Unix epoch timestamp.

There are 60 seconds in a minute, 60 minutes in an hour, 24 hours in a day. So we can just use 60 × 60 × 24 = 86400 seconds per day and count the days backwards until 1970-01-01T00:00:00Z, right? Months have different numbers of days, though. So it's probably better to skip that and use 365 days per year. But then, there's leap years... and leap seconds... and more?

Does that suddenly make the algorithm as complex as dealing with timezones or is it still fairly easy to describe?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文