定制 robertocemeri/date-utils 二次开发

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

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

robertocemeri/date-utils

最新稳定版本:v1.0.0

Composer 安装命令:

composer require robertocemeri/date-utils

包简介

A simple and lightweight PHP library for date and time operations with timezone support

README 文档

README

Latest Version on Packagist

A lightweight PHP library for easy date and time operations with timezone support.

Installation

composer require robertocemeri/date-utils

Usage

Basic Usage

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

use function RobertoCemeri\DateUtils\{
    currentDate, 
    currentYear, 
    currentTime
};

// Get current date
echo currentDate(); // "2024-01-15"
echo currentDate('DD/MM/YYYY'); // "15/01/2024"

// Get current year
echo currentYear(); // 2024

// Get current time
echo currentTime(); // "14:30:25"
echo currentTime('HH:mm'); // "14:30"

Advanced Usage with Timezone

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

use RobertoCemeri\DateUtils\DateUtils;

$utils = new DateUtils();
echo $utils->currentDate(); // "2024-01-15"
echo $utils->currentYear(); // 2024

Class-based Usage

<?php
use RobertoCemeri\DateUtils\DateUtils;

$utils = new DateUtils('Asia/Tokyo');
echo $utils->currentYear(); // 2024
echo $utils->currentDate('Y/m/d'); // "2024/01/16"

API Reference

Convenience Functions

  • currentDate($format = 'Y-m-d') - Get current date
  • currentYear() - Get current year
  • currentTime($format = 'H:i:s') - Get current time
  • currentDateTime($format = 'Y-m-d H:i:s') - Get current date and time
  • timestamp() - Get current timestamp

DateUtils Class

  • __construct($timezone = 'local')
  • setTimezone($timezone) - Set timezone
  • currentDate($format) - Get current date
  • currentYear() - Get current year
  • currentTime($format) - Get current time
  • currentDateTime($format) - Get current date and time
  • timestamp() - Get timestamp
  • addDays($days) - Add days to current date
  • subtractDays($days) - Subtract days from current date

Format Options

Custom Format Tokens

  • YYYY - Four-digit year (2024)
  • YY - Two-digit year (24)
  • MM - Two-digit month (01-12)
  • M - Month (1-12)
  • DD - Two-digit day (01-31)
  • D - Day (1-31)
  • HH - Two-digit hour (00-23)
  • H - Hour (0-23)
  • mm - Two-digit minutes (00-59)
  • ss - Two-digit seconds (00-59)
  • SSS - Milliseconds (000-999)

Standard PHP Formats

You can also use standard PHP date format characters.

Timezone Support

Use any valid PHP timezone:

  • 'local' - System local time (default)
  • 'UTC' - UTC time
  • 'America/New_York' - Eastern Time
  • 'Europe/London' - GMT/BST
  • 'Asia/Tokyo' - Japan Standard Time

Get all available timezones:

$timezones = DateUtils::getAvailableTimezones();

License

MIT

Author

Roberto Cemeri robertocemeri29@gmail.com

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-16