定制 phputil/tdatetime 二次开发

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

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

phputil/tdatetime

最新稳定版本:1.1.1

Composer 安装命令:

composer require phputil/tdatetime

包简介

Extends the features of PHP's DateTime

README 文档

README

Build Status

Easy-to-use date and time extensions for PHP's DateTime class.

  • No external dependencies.
  • Unit-tested
  • Semantic versioning
  • PHP >= 5.2

Installation

Installation via Composer:

composer require phputil/tdatetime

Documentation

Available classes:

📖 See the Wiki.

Examples

<?php
require 'vendor/autoload.php';

use phputil\TDateTime; // Allow to use TDateTime without the namespace name

// Creating a datetime
$dt1 = new TDateTime( '2015-01-20 09:10:55' );
echo $dt1; // 2015-01-20 09:10:55

// Creating a datetime with timezone
$dt1 = new TDateTime( '2015-01-20 09:10:55', new \DateTimeZone( 'America/Sao_Paulo' ) );
echo $dt1;

// Easy-to-use methods to get/change date and time attributes
$dt1->addOneDay();        // Adds one day
echo $dt1->day();         // 21
echo $dt1->dateString();  // 2015-01-21
echo $dt1->timeString();  // 09:10:55

// Clonnable
$dt2 = clone $dt1;
echo $dt2; // 2015-01-21 09:10:55

// Chainnable setter methods
$dt2->subYears( 1 )->addMonths( 11 )->setDay( 31 ); // 2014-12-31

// Allow to change the format for the current instance
$dt2->setLocalDateTimeFormat( TDateTime::AMERICAN_DATETIME_FORMAT );
echo $dt2; // 12/31/2014 09:10:55

// Allow to change the format of ALL instances, but respect local format modifications!
TDateTime::setGlobalDateTimeFormat( TDateTime::BRAZILIAN_DATETIME_FORMAT );
echo $dt1; // 21/01/2015 09:10:55 -> Brazilian datetime format
echo $dt2; // 12/31/2014 09:10:55 -> American datetime format (respect local formatting)

// Easy comparison
echo $dt2->before( $dt1 ); // true
echo $dt1->between( $dt2, new TDateTime() ); // true
echo $dt1->equalTo( $dt2 ) ? '=' : '!='; // !=

// Validation (version 1.1+)
echo $dt1->isValidDatabaseDate( '2000/01/31' ); // true
echo $dt1->isValidAmericanDate( '01/31/2000' ); // true
echo $dt1->isValidBrazilianDate( '31/01/2000' ); // true
echo $dt1->isValidDatabaseDateTime( '2000/01/31 23:59:59' ); // true
echo $dt1->isValidAmericanDateTime( '01/31/2000 23:59:59' ); // true
echo $dt1->isValidBrazilianDateTime( '31/01/2000 23:59:59' ); // true
echo $dt1->isValidTime( '23:59:59' ); // true
echo $dt1->isValidSimpleTime( '23:59' ); // true
?>

License

LGPL © Thiago Delgado Pinto

统计信息

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

GitHub 信息

  • Stars: 4
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-3.0-or-later
  • 更新时间: 2015-01-24