PHP code example of muhammad-zahid / universaldate

1. Go to this page and download the library: Download muhammad-zahid/universaldate library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

muhammad-zahid / universaldate example snippets


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

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();

use MuhammadZahid\UniversalDate\UniversalDate;

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