leviferreira/melody-datetime

PHP的DateTime扩展

dev-master 2015-07-10 17:47 UTC

This package is not auto-updated.

Last update: 2024-09-28 15:12:00 UTC


README

Join the chat at https://gitter.im/project-melody/datetime

Build Status

安装

推荐安装Melody DateTime的方式是通过composer。只需创建一个composer.json文件,并运行php composer.phar install命令即可安装。

    {
        "require": {
            "project-melody/datetime": "dev-master"
        }
    }

介绍

导入DateTime命名空间

use Melody\DateTime\DateTime;

基本用法

向日期添加工作日

    // Sets the datetime, will consider the 'now' date
    // for example: 2013-12-01 00:00:00
    $datetime = new DateTime();
    
    // add two business days to a date
    $datetime->addBusinessDays(2);

    // Output: 2013-12-03 00:00:00
    echo $datetime->format('Y-m-d H:i:s');

向日期添加工作日,考虑节假日

    // Sets the datetime, will consider the 'now' date
    // for example: 2013-12-01 00:00:00
    $datetime = new DateTime();
    
    // Set a list of holidays that will be considered
    $datetime->setHolidays(array('2013-12-02'));

    // Add two business days to a date, considering holidays as non-business days
    $datetime->addBusinessDaysWithHolidays(2);

    // Output: 2013-12-04 00:00:00
    echo $datetime->format('Y-m-d H:i:s');