PHP code example of vincenzoraco / date-formatter-php

1. Go to this page and download the library: Download vincenzoraco/date-formatter-php 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/ */

    

vincenzoraco / date-formatter-php example snippets


(new FormatDate(CarbonImmutable::now()))
  ->add(new Rfc822Formatter)
  ->add(new Rfc850Formatter)
  ->add(new Iso8601Formatter)
  ->add((new TimestampFormatter)->setKey("unix"))
  ->toArray();

// Result
[
    "rfc_822" => "Sun, 02 Mar 25 09:25:01 +0000",
    "rfc_850" => "Sunday, 02-Mar-25 09:25:01 UTC",
    "iso_8601" => "2025-03-02T09:25:01+00:00",
    "unix" => "1740907501",
]

use VincenzoRaco\DateFormatterAbstract;

class CustomFormatter extends DateFormatterAbstract
{
    protected string $key = 'custom_key';

    public function __toString(): string
    {
        return $this->getDate()->format('d/m/Y');
    }
}
bash
composer