12

我正在Java 世界中寻找像Joda-Time这样的库(开源) 。有没有这样的图书馆?

Joda-Time 对计算日期和时间非常有帮助。我可以添加天、周、月、年,也可以轻松转换日期和时间。

我希望有像 Joda-Time for PHP 这样的库。

编辑:我需要一些在 Joda-Time 中可用的函数,例如 daysBetween(计算两个日期之间的天数)、monthsBetween 和 weekBetween ... PHP 本身提供了一些关于添加和减去日期的函数。

4

6 回答 6

4

这就是你要找的东西:https ://github.com/briannesbitt/Carbon

于 2013-07-04T19:25:16.407 回答
0

你可以试试这个库的 PHP 日期和时间 http://nuclearscripts.com/php/scripts-and-programs/date-and-time/php-date-library.html

从那里引用

PHP 日期库是处理日期的专业原生 PHP 函数的集合。它不需要任何 PHP 扩展。该库包含处理日期的最有用的函数。它包括验证日期、按给定天数移动日期、计算两个日期之间的差异、计算给定日期的周数等功能。它可以正确处理闰年并且与 ISO 兼容。专业程序员花了 3 天以上的时间来学习该主题,编写库代码,编写手册并将其全部放在这里。

我没有亲自测试过。

于 2009-08-31T06:35:14.487 回答
0

我知道Zend 框架的一个组件:Zend_Date。它适用于这项工作。

我不确定,但你可以在没有整个框架的情况下使用它。

Zend 日期

于 2009-08-25T04:22:45.147 回答
0

我对 Joda 不熟悉,但你看过DateTime吗?它完成了您提到的所有事情(以及更多事情)。

于 2009-08-25T04:23:03.537 回答
0

strtotime并且date有时可以创造奇迹,特别是如果您使用的日期 >= 1970 (即,可以编码为 UNIX 时间戳)

如果您使用的是最新版本的 PHP,那么DateTime该类(在 PHP 5.2 中添加;但在 PHP 5.3 中添加了几个方法)也可能会有所帮助——其他Date 和 Time类也可能会有所帮助。

于 2009-08-25T04:24:21.117 回答
-2

不需要外部库。PHP 已经能够做到这一点。

<?php
/** These examples work with the current time **/
echo strtotime("now"), "\n";
echo strtotime("10 September 2000"), "\n";
echo strtotime("+1 day"), "\n";
echo strtotime("+1 week"), "\n";
echo strtotime("+1 week 2 days 4 hours 2 seconds"), "\n";
echo strtotime("next Thursday"), "\n";
echo strtotime("last Monday"), "\n";

/** This is a made up time **/
$lessMonth = strtotime("06/19/1986 3:00PM")
$lessMonth = strtotime("-1 month", $lessMonth);

echo $lessMonth, "\n";
echo gmdate('c', $lessMonth);

/** 86 400 seconds in a day */
$daysBetween = (strtotime("now") - $lessMonth) / 86400
?> 
于 2009-08-30T09:45:21.887 回答