Date and Time helper for PHP (like Joda-Time in Java) [closed]

不羁岁月 提交于 2019-12-05 01:54:19

This is what you are looking for : https://github.com/briannesbitt/Carbon

I'm not familiar with Joda, but did you took a look into DateTime? It does all the things (and some more) that you've mentioned.

strtotime and date can sometimes do wonders, especially if you are working with dates >= 1970 (ie, which can be coded as a UNIX timestamp).

If you are using a recent enough version of PHP, the DateTime class (added in PHP 5.2 ; but several methods were added in PHP 5.3) might be helpful too -- other Date and Time classes could help, too.

You can try this library for PHP Date and time http://nuclearscripts.com/php/scripts-and-programs/date-and-time/php-date-library.html

Quoting from there

The PHP Date Library is collection of professional native PHP functions to work with dates. It does not require any PHP extensions. This library includes most useful functions to work with dates. It includes functions to validate the date, shift date by given amount of days, calculate difference between two dates, calculate week number for given date and much more. It properly handles leap years and is ISO compatible. Professional programmer has spent 3+ days to study the subject, code the library, write manual and put it all here.

I havn't tested it personally.

opHASnoNAME

I know a component of the Zend Framework: Zend_Date. It works fine for this job.

I am not sure, but you can use it without the whole Framework.

Zend Date

There is no need for external library. PHP is more than capable of this already.

<?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
?> 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!