PHP code example of meysampg / intldate

1. Go to this page and download the library: Download meysampg/intldate 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/ */

    

meysampg / intldate example snippets


use meysampg\intldate\IntlDateTrait;



namespace foo\bar;

use meysampg\intldate\IntlDateTrait;

class Bar
{
  use IntlDateTrait;
  // Some codes are here!
 
  echo $this->fromGregorian([2017, 9, 7, 12, 23, 45])->toPersian('en')->asDateTime();
}

[
    year, // 2016
    month, // 2
    day, // 23
    hour, // 12
    minute, // 23
    second // 4
]

// Use them in `self::$CAL_CALENDAR, for example `$calendar = self::$CAL_HEBREW`.
$CAL_PERSIAN
$CAL_JAPANESE
$CAL_BUDDHIST
$CAL_CHINESE
$CAL_INDIAN
$CAL_ISLAMIC
$CAL_HEBREW
$CAL_COPTIC
$CAL_ETHIOPIC
$CAL_GREGORIAN

$this->fromTimestamp(1504770825)->toPersian('en')->asDateTime();
// '1396/06/16, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toPersian('en')->asDateTime();
// '1396/06/16, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toPersian()->asDateTime();
// '۱۳۹۶/۰۶/۱۶, ۰۷:۵۳:۴۵'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toJapanese()->asDateTime();
// '0029/09/07, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toIslamic()->asDateTime();
// '١٤٣٨/١٢/١٧, ٠٧:٥٣:٤٥'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toBuddhist()->asDateTime();
// '2560/09/07, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toChinese()->asDateTime();
// '0034/07/17, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toIndian()->asDateTime();
// '1939/06/16, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toHebrew()->asDateTime();
// 'תשע״ז/י״ב/ט״ז, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toCoptic()->asDateTime();
// '1733/13/02, 07:53:45'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->toEthiopic()->asDateTime();
// '2009/13/02, 07:53:45'

$this->fromPersian([1396, 6, 16, 12, 23, 45])->toIslamic()->asDateTime();
// '١٤٣٨/١٢/١٧, ٠٧:٥٣:٤٥'

$this->fromPersian([1396, 6, 16, 12, 23, 45])->toGregorian()->asDateTime();
// '2017/09/07, 07:53:45'

$this->fromPersian([1396, 6, 16, 12, 23, 45])->toGregorian()->setFinalTimeZone('Asia/Tehran')->asDateTime();
// '2017/09/07, 12:23:45'

$this->fromPersian([1396, 6, 16, 12, 23, 45])->toGregorian()->setFinalTimeZone('Asia/Tehran')->asDateTime('yyyy');
// '2017'

$this->fromGregorian([2017, 9, 7, 12, 23, 45])->asTimestamp();
// '1504770825'

$this->fromPersian([1396, 6, 16, 12, 23, 45])->asTimestamp();
// '1504770825'

/**
 * Implement a function to parse both ICU patterns and php date
 * function patterns and return a pattern that is compatible on
 * ICU format. The php pattern must start with php keyword, for
 * example `php:Y-F-d, H:i:s` is a php pattern.
 */