伪代码算法从给定的日期和时间开始计算UNIX Epoch时间戳?
给定的UTC日期和时间为年
,月
,day
,hour
,分钟 ,第二
,我想知道一个伪代码算法来计算相应的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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论