代表一天的最佳格式是什么?

发布于 2024-07-07 17:47:22 字数 104 浏览 7 评论 0原文

如何表示一天的开始时间和结束时间?

以2008年10月23日为例,是从2008-10-23 12:00:00 AM开始,到2008-10-23 11:59:59 PM结束吗?

How to represent the start and end times for one day?

Using October 23, 2008 as an example, is it start 2008-10-23 12:00:00 AM and end 2008-10-23 11:59:59 PM?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

雄赳赳气昂昂 2024-07-14 17:47:22

我想引用一个网站,http://www.cl。 cam.ac.uk/~mgk25/iso-time.html

一天中时间的国际标准表示法是,

hh:mm:ss

其中 hh 是自午夜 (00-24) 以来经过的完整小时数,mm 是自小时开始 (00-59) 以来经过的完整分钟数,ss 是自分钟开始 (00-60) 以来经过的完整秒数。 如果小时值为 24,则分钟和秒值必须为零。

注意:在原子时标(如协调世界时 (UTC))中插入闰秒期间,有时可能需要 ss 的值 60。 巴黎国际地球自转服务组织宣布,每隔几年就会在 UTC 时标中插入一个闰秒 23:59:60,以防止 UTC 偏离不太恒定的天文时标 UT1 超过 0.9 秒。由地球的实际自转定义。 实际上,您不太可能看到时钟显示 23:59:60。 大多数同步时钟会在闰秒发生后的某个时间再次重新同步到 UTC,或者在接近闰秒的时间时暂时减慢速度,以避免超出范围的时间戳可能导致的任何中断。

一个示例时间是

23:59:59

表示午夜前一秒的时间。

与日期表示法一样,分隔冒号也可以省略,如 所示,

235959

并且可以通过省略秒或秒和分钟来降低精度,如

23:59, 2359, or 23

还可以在小数点或逗号后添加秒的小数部分,例如,午夜前 5.8 毫秒的时间可以写为

23:59:59.9942 or 235959.9942

由于每天都以午夜开始和结束,因此可以使用 00:00 和 24:00 两种表示法来区分与一个日期关联的两个午夜。 这意味着以下两个表示法指的是完全相同的时间点:

1995-02-04 24:00 = 1995-02-05 00:00

如果需要明确的时间表示法,则 00:00 通常是午夜的首选表示法,而不是 24:00。 数字时钟显示 00:00 而不是 24:00。

ISO 8601 没有指定其符号是否指定时间点或时间段。 例如,这意味着 ISO 8601 没有定义 09:00 是指一天中第九个小时的确切结束时间,还是指从 09:00 到 09:01 的时间段或其他时间。 如果有任何问题,标准的用户必须以某种方式就时间符号的确切解释达成一致。

如果日期和时间显示在同一行,则始终将日期写在时间前面。 如果日期和时间值一起存储在单个数据字段中,则 ISO 8601 建议应使用拉丁大写字母 T 分隔它们,如 19951231T235959。

致美国读者的一句话:

这里规定的24小时时间表示法几十年来已经成为全世界书面语言的事实上的标准。 唯一的例外是一些英语国家,这些国家仍然广泛使用 1 到 12 之间的小时符号以及“am”和“pm”等附加符号。 通用的 24 小时国际标准符号现在甚至在英国也被广泛使用(例如在机场、电影院、公共汽车/火车时刻表等)。 大多数其他语言甚至没有像“am”和“pm”这样的缩写,而且欧洲大陆几乎从未使用 12 小时表示法来书写或显示时间。 即使在美国,军队和计算机程序员也很长时间以来都在使用 24 小时表示法。

旧的英文 12 小时表示法有许多缺点,例如:

  • 它比正常的 24 小时表示法更长。
  • 人类以 12 小时表示法比较两个时间需要花费更多的时间。
  • 目前尚不清楚 00:00、12:00 和 24:00 是如何表示的。 即使百科全书和风格手册也包含相互矛盾的描述,一个常见的快速解决办法似乎是完全避免“12:00 am/pm”,而写“noon”、“midnight”或“12:01 am/pm”,尽管“午夜”一词仍然无法区分 00:00 和 24:00(给定一天的开始或结束时的午夜)。
  • 它使人们常常相信第二天从“凌晨 12:59”到“凌晨 1:00”的溢出开始,这不仅是当人们试图在午夜过后不久对录像机定时器进行编程时,这是一个常见问题。
  • 它不容易与字符串比较操作进行比较。
  • 对于不知情的人来说,并不能立即清楚“12:00 am/pm”和“1:00 am/pm”之间的时间是从 00:00 还是从 12:00 开始,即英语 12h 表示法更难理解理解。

请考虑 12 小时时间是黑暗时代的遗迹,当时使用罗马数字,数字零尚未发明,模拟时钟是唯一已知的显示时间的形式。 今天请避免使用它,尤其是在技术应用中! 即使在美国,广受推崇的《芝加哥风格手册》现在也建议在出版物中使用国际标准时间表示法。

I would like to cite a site, http://www.cl.cam.ac.uk/~mgk25/iso-time.html

The international standard notation for the time of day is

hh:mm:ss

where hh is the number of complete hours that have passed since midnight (00-24), mm is the number of complete minutes that have passed since the start of the hour (00-59), and ss is the number of complete seconds since the start of the minute (00-60). If the hour value is 24, then the minute and second values must be zero.

Note: The value 60 for ss might sometimes be needed during an inserted leap second in an atomic time scale like Coordinated Universal Time (UTC). A single leap second 23:59:60 is inserted into the UTC time scale every few years as announced by the International Earth Rotation Service in Paris, to keep UTC from wandering away more than 0.9 s from the less constant astronomical time scale UT1, which is defined by the actual rotation of the earth. In practice you are not very likely to see a clock showing 23:59:60. Most synchronized clocks resynchronize again to UTC some time after a leap second has happened, or they temporarily slow down near the time of a leap seconds, to avoid any disruption that an out-of-range timestamp might otherwise cause.

An example time is

23:59:59

which represents the time one second before midnight.

As with the date notation, the separating colons can also be omitted as in

235959

and the precision can be reduced by omitting the seconds or both the seconds and minutes as in

23:59, 2359, or 23

It is also possible to add fractions of a second after a decimal dot or comma, for instance the time 5.8 ms before midnight can be written as

23:59:59.9942 or 235959.9942

As every day both starts and ends with midnight, the two notations 00:00 and 24:00 are available to distinguish the two midnights that can be associated with one date. This means that the following two notations refer to exactly the same point in time:

1995-02-04 24:00 = 1995-02-05 00:00

In case an unambiguous representation of time is required, 00:00 is usually the preferred notation for midnight and not 24:00. Digital clocks display 00:00 and not 24:00.

ISO 8601 does not specify, whether its notations specify a point in time or a time period. This means for example that ISO 8601 does not define whether 09:00 refers to the exact end of the ninth hour of the day or the period from 09:00 to 09:01 or anything else. The users of the standard must somehow agree on the exact interpretation of the time notation if this should be of any concern.

If a date and a time are displayed on the same line, then always write the date in front of the time. If a date and a time value are stored together in a single data field, then ISO 8601 suggests that they should be separated by a latin capital letter T, as in 19951231T235959.

A remark for readers from the U.S.:

The 24h time notation specified here has already been the de-facto standard all over the world in written language for decades. The only exception are a few English speaking countries, where still notations with hours between 1 and 12 and additions like “a.m.” and “p.m.” are in wide use. The common 24h international standard notation is widely used now even in England (e.g. at airports, cinemas, bus/train timetables, etc.). Most other languages do not even have abbreviations like “a.m.” and “p.m.” and the 12h notation is certainly hardly ever used on Continental Europe to write or display a time. Even in the U.S., the military and computer programmers have been using the 24h notation for a long time.

The old English 12h notation has many disadvantages like:

  • It is longer than the normal 24h notation.
  • It takes somewhat more time for humans to compare two times in 12h notation.
  • It is not clear, how 00:00, 12:00 and 24:00 are represented. Even encyclopedias and style manuals contain contradicting descriptions and a common quick fix seems to be to avoid “12:00 a.m./p.m.” altogether and write “noon”, “midnight”, or “12:01 a.m./p.m.” instead, although the word “midnight” still does not distinguish between 00:00 and 24:00 (midnight at the start or end of a given day).
  • It makes people often believe that the next day starts at the overflow from “12:59 a.m.” to “1:00 a.m.”, which is a common problem not only when people try to program the timer of VCRs shortly after midnight.
  • It is not easily comparable with a string compare operation.
  • It is not immediately clear for the unaware, whether the time between “12:00 a.m./p.m.” and “1:00 a.m./p.m.” starts at 00:00 or at 12:00, i.e. the English 12h notation is more difficult to understand.

Please consider the 12h time to be a relic from the dark ages when Roman numerals were used, the number zero had not yet been invented and analog clocks were the only known form of displaying a time. Please avoid using it today, especially in technical applications! Even in the U.S., the widely respected Chicago Manual of Style now recommends using the international standard time notation in publications.

绻影浮沉 2024-07-14 17:47:22

当然,如果您只想表示 1 天,则根本不需要包含时间 - 特别是因为这会引发有关一天何时开始或结束的讨论。 根据我的经验,日期处理通常足够复杂,不会引入任何额外的复杂性。

今天是 2008 年 10 月 20 日 - 无需提供更多信息。

或者我错过了什么?

Surely, if you just want to represent 1 day, you don't need to include the time at all - especially as this raises such a level of discussion about when a day starts or ends. In my experience, date handling is usually complicated enough, without introducing any extra complexity.

Today is Oct 20th 2008 - no more information is necessary.

Or am I missing something?

萝莉病 2024-07-14 17:47:22

10 月 23 日从 2008 年 10 月 23 日上午 12 点开始,到 2008 年 10 月 24 日上午 12 点结束——一天的结束时间与下一天的开始时间完全相同。 最后一秒从晚上 11:59:59 开始,但距离一天结束还有一整秒的时间。

Oct. 23 starts at 2008-10-23 12AM and finishes at 2008-10-24 12AM—a day ends at the exact same point the next one begins. The very last second begins at 11:59:59 PM but you still have a whole second before the day is over.

醉殇 2024-07-14 17:47:22

你的记法很奇怪。 我建议指定全天范围的标准方法是:

2008-10-23 00:00:00 并完成 2008-10-23 23:59:59

Your notation is strange. I'd suggest the standard way of specifying a full day range is:

2008-10-23 00:00:00 and finish 2008-10-23 23:59:59

雪化雨蝶 2024-07-14 17:47:22

您在问题中提到的日期的定义是 >= 2008-10-23 00:00:00 和 <= 的任何时间 2008-10-24 00:00:00 。

The definition of the day you mention in the question is any time that is >= 2008-10-23 00:00:00 and < 2008-10-24 00:00:00 .

治碍 2024-07-14 17:47:22

如果您要使用数学区间表示法,您可以将其写为

[2008-10-23 00:00:00 , 2008-10-24 00:00:00)

[ 表示包含,) 表示最多但不包括。

通过这种方式,您可以让用户和您自己变得更轻松。

If you were to use mathematical interval notation, you would write it as

[2008-10-23 00:00:00 , 2008-10-24 00:00:00)

The [ means inclusion, and ) means up to but not including.

In this way you make it easier for users and for yourself.

因为看清所以看轻 2024-07-14 17:47:22

这取决于你所说的一天是什么意思。 遗憾的是,日期处理总是比看起来更复杂。

要将示例转换为 24 小时 ISO 日期格式,您可以这样说:

2008-10-23 00:00:00 - 2008-10-23 23:59:59

但是,这取决于您将范围解释为包含范围还是排除范围,这可能会省略当天的最后一秒*。 程序员通常更喜欢保持上限的排他性,所以你会选择:

2008-10-23 00:00:00 - 2008-10-24 00:00:00

或者,作为一种更好的表述方式,如果支持(或为了人类可读性):

2008-10-23 00:00:00 - 2008-10-23 24:00:00

*:实际上可能不止一个。 如果跨度代表 UTC 时区(或与其对齐的另一个时区,这很可能)中的一天,则在一天结束时偶尔会出现一个额外的“闰秒”,即 23:59:60,这是毫无意义的。尝试使 UTC 与恒星时保持一致。 下一次闰秒计划在今年年底进行。 然而,许多系统忽略闰秒,因为它们既愚蠢又烦人。

如果您想表示独立于时区的“日历日”,最好的选择是儒略日数。 今天是 2454760。

It depends what you mean by a day. Date handling is, sadly, always more complex than it looks.

To convert your example into 24h ISO date format, you'd say:

2008-10-23 00:00:00 - 2008-10-23 23:59:59

However depending on whether you interpret a range as inclusive or exclusive that could omit the last second of the day*. Programmers normally prefer to keep the upper bound exclusive, so you'd go for:

2008-10-23 00:00:00 - 2008-10-24 00:00:00

Or, as a slightly nicer way of stating the same, if supported (or for human readability):

2008-10-23 00:00:00 - 2008-10-23 24:00:00

*: actually possibly more than one. If the span represents a day in the UTC timezone (or another timezone aligned to it, which is quite likely), there can occasionally be an extra 'leap second' at the end of the day, 23:59:60, in a pointless attempt to keep UTC in line with sidereal time. The next leap second is planned for the end of this year. However, many systems ignore leap seconds because they're silly and annoying.

If you want to represent a 'calendar day' independently of timezones your best bet is the Julian day number. Today is 2454760.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文