如何在 PHP 中处理 1900 年之前的日期?
我正在使用 PHP 和 jQuery 构建一个交互式时间线,需要显示 1500 年到 2020 年之间的日期。在处理日期时,我通常使用 PHP 的 strtotime
函数,但它不适用于 1900 年之前的日期。
日期将来自 MySQL 数据库,并被格式化为字符串,例如“1654 年 1 月 31 日
”(这可能不是理想的格式,但我无法更改它们的存储方式)。我使用 PHP 来解析日期,基本上将它们转换为像素值,以确定它们在时间轴上的显示位置。
解析这些历史日期的最简单方法是什么?
I am using PHP and jQuery to build an interactive timeline which needs to display dates between 1500 and 2020. I usually use PHP's strtotime
function when working with dates, but it does not work for dates pre-1900.
The dates will come from a MySQL database, and are formatted as strings such as "January 31, 1654
" (this may not be the ideal format, but I can't change how they are stored). I am using PHP to parse the dates, basically converting them into pixel values which determine where they are displayed on the timeline.
What is the easiest way to parse these historical dates?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里的
DateTime
类可能会有所帮助(引用):但请注意:
因此:如果您在 PHP 5.3 上进行开发并希望您的软件兼容,请注意您使用的方法使用 PHP 5.2
另一个解决方案(特别是,如果在应用程序中使用 Zend Framework) 是
Zend_Date
组件 (引用):The
DateTime
class, here, might help (quoting):But note that:
So: beware of which methods you're using, if you're developping on PHP 5.3 and want your software to be compatible with PHP 5.2
Another solution (especially, if using Zend Framework in your application) would be the
Zend_Date
component (quoting):使用精彩的 Carbon Library,过去的日期不是问题:
这适用于人类所处的日期已经在附近了。对于其他所有内容,使用日期(包含日和月,按 AC/BC 比例设置)没有多大意义。
Using the wonderful Carbon Library, dates in the past are not a problem:
This works for dates where humans have been around. For everything else, using a date (with day and month, set on the AC/BC scale) does not make a lot of sense.