定制 craigsefton/chronos 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

craigsefton/chronos

Composer 安装命令:

composer require craigsefton/chronos

包简介

Extensions to the standard PHP DateTime class.

README 文档

README

Installation

Via Composer

  1. Run the command: composer require "craigsefton/chronos:*"

Manual Installation

  1. Clone this repository: git clone git@github.com:craigsefton/chronos.git
  2. Change to the cloned folder, e.g.: cd chronos
  3. Run command composer install

Testing Your Installation

All tests are built using PHPUnit, which should have been installed as part of the composer installation (PHPUnit is a dev dependency).

To run all tests, run the command vendor/bin/phpunit from within the Chronos folder.

Example Usage

This extends the default PHP DateTime class, and provides some additional functionality. All methods manipulate the current object, unless stipulated otherwise. In addition, all methods return the current object, so methods can be chained, if desired.

use \Chronos\ChronosDateTime;
$date = new ChronosDateTime("2015-03-15 23:00:00");
echo $date->endOfYear()->startOfDay();
// Prints Thu, 31 Dec 2015 00:00:00 +0000

As you can see, you can also print objects. A default format for printing can be set using $date->setDefaultFormat().

Timezones

One import thing to note is that the default TimeZone for Chronos is UTC. Otherwise, usage of TimeZones works the same as the normal DateTime library.

Start of week

In addition, the library treats the starting day of a week to be Monday, and the end of the week to be Sunday.

use \Chronos\ChronosDateTime;
$date = new ChronosDateTime("2015-03-15 23:00:00");
echo $date->startOfFirstDayOfWeek();
// Prints Mon, 09 Mar 2015 00:00:00 +0000

Date Validation

The class also implements an excellent date validator, taken from http://php.net/function.checkdate#113205

use \Chronos\ChronosDateTime;
// False
echo ChronosDateTime::validateDate('2012-02-30 12:12:12');
echo ChronosDateTime::validateDate('14:77', 'H:i');
// True
echo ChronosDateTime::validateDate('Tue, 28 Feb 2012 12:12:12 +0200', 'D, d M Y H:i:s O');

统计信息

  • 总下载量: 17
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 2
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-03-07

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固