ruby - 为什么 Date 类的新实例的默认年份等于 -4712?

标签 ruby

运行:

require 'date'
y = Date.new
puts "default year is #{y.year}"

输出:

default year is -4712

Date 对象的年份默认为 -4712 是否有任何特殊原因?我认为也许有技术(或传统)原因。我用谷歌搜索并在 Ruby 文档 (2.2.3) 中查找了它,但我找不到关于为什么的答案。

最佳答案

公元前 4713 年 1 月 1 日是 Julian day 的开始, 来自维基:

The Julian Day Number (JDN) is the integer assigned to a whole solar day in the Julian day count starting from noon Greenwich Mean Time, with Julian day number 0 assigned to the day starting at noon on January 1, 4713 BC, proleptic Julian calendar (November 24, 4714 BC, in the proleptic Gregorian calendar), a date at which three multi-year cycles started and which preceded any historical dates. For example, the Julian day number for the day starting at 12:00 UT on January 1, 2000, was 2,451,545.

这一天的年份是公元前 4713 年,或者严格来说是 -4712

关于ruby - 为什么 Date 类的新实例的默认年份等于 -4712?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33717695/

相关文章:

ruby-on-rails - 使用 Active Admin 访问 Active Storage 模型

ruby - 如何测试模块中的私有(private)函数

ruby - 如何在 ruby​​ 中执行 attr_accessor_with_default?

ruby-on-rails - Rails - redirect_to 没有按预期发送参数

ruby-on-rails - 如何收集当月包含的对象集合

ruby-on-rails - 验证 rails 中是否存在多个属性之一

ruby - 构建 Gem 时出错

ruby - 如何在 Ruby 中使用 Logger 而不是 put 而不使用全局变量

ruby - 尝试图像抓取时出错

javascript - ruby 变量在 driver.execute_script 之后返回 nil