muhammad-zahid/universaldate 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

muhammad-zahid/universaldate

最新稳定版本:v1.1.3

Composer 安装命令:

composer require muhammad-zahid/universaldate

包简介

This package will convert any type of date to human readable date

README 文档

README

A powerful PHP package for converting dates into human-readable formats with Laravel integration support. Convert any type of date format into user-friendly, readable text with support for multiple languages and "time ago" formatting.

Features

  • 🔄 Convert any date format to human-readable text
  • ⏰ "Time ago" formatting (e.g., "2 hours ago", "in 3 days")
  • 🌍 Timezone support
  • 🔌 Seamless Laravel integration
  • 🎯 Support for multiple date input formats (string, timestamp, DateTime)
  • 🛠️ Customizable output formats
  • 🚀 Simple and intuitive API

Requirements

  • PHP 7.4 or higher
  • Laravel 8.0+ (for Laravel integration)

Installation

Install the package via Composer:

composer require muhammad-zahid/universaldate

Basic Usage

use MuhammadZahid\UniversalDate\UniversalDate;

// Initialize with current date
$date = new UniversalDate();
echo $date->toHuman(); // "January 5, 2024 at 9:30 PM"

// Initialize with a specific date
$date = new UniversalDate('2023-12-25');
echo $date->toHuman(); // "December 25, 2023 at 12:00 AM"

// Time ago format
$date = new UniversalDate('2023-12-25');
echo $date->toTimeAgo(); // "11 days ago"

// Custom format
$date = new UniversalDate('2023-12-25');
echo $date->format('Y-m-d'); // "2023-12-25"

// With timezone
$date = new UniversalDate('2023-12-25', 'America/New_York');
echo $date->toHuman(); // Shows date in New York timezone

Laravel Integration

The package includes Laravel integration with a Facade for convenient usage.

Using the Facade

use MuhammadZahid\UniversalDate\Facades\UniversalDate;

// Quick usage
echo UniversalDate::toHuman(); // Current date in human format

// Chain methods
echo UniversalDate::make('2023-12-25')
    ->setTimezone('America/New_York')
    ->toHuman();

// Time ago
echo UniversalDate::make('2023-12-25')->toTimeAgo();

Using Dependency Injection

use MuhammadZahid\UniversalDate\UniversalDate;

class DateController
{
    public function show(UniversalDate $date)
    {
        return $date->toHuman();
    }
}

Available Methods

Main Methods

  • toHuman(?string $format = null): string Converts date to human-readable format

  • toTimeAgo(): string Shows relative time (e.g., "2 hours ago")

  • format(string $format): string Formats date according to specified format string

  • getDateTime(): DateTime Returns the underlying DateTime instance

  • setTimezone(string $timezone): self Sets the timezone for the date

Static Creation (Laravel Facade)

  • make(string|int|DateTime $date = 'now', ?string $timezone = 'UTC'): UniversalDate Creates a new UniversalDate instance

License

The UniversalDate package is open-sourced software licensed under the MIT license.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

Support

If you have any questions or run into any issues, please create an issue on the GitHub repository.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-05