PHP code example of andhikamaheva / date

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

    

andhikamaheva / date example snippets


'Jenssegers\Date\DateServiceProvider',

'Date' => Jenssegers\Date\Date::class,

use Jenssegers\Date\Date;

Date::setLocale('nl');

echo Date::now()->format('l j F Y H:i:s'); // zondag 28 april 2013 21:58:16

echo Date::parse('-1 day')->diffForHumans(); // 1 dag geleden

echo $date->timespan(); // 3 months, 1 week, 1 day, 3 hours, 20 minutes

$date = Date::createFromFormat('l d F Y', 'zaterdag 21 maart 2015');

$date = new Date();
$date = new Date('2000-01-31');
$date = new Date('2000-01-31 12:00:00');

// With time zone
$date = new Date('2000-01-31', new DateTimeZone('Europe/Brussels'));

$date = new Date('2000-01-31', 'Europe/Brussels');

$date = new Date('now');
$date = new Date('today');
$date = new Date('+1 hour');
$date = new Date('next monday');

$date = Date::parse('now');
$date = Date::now();

$date = new Date(1367186296);

$date = Date::createFromDate(2000, 1, 31);
$date = Date::createFromTime(12, 0, 0);
$date = Date::create(2000, 1, 31, 12, 0, 0);

echo Date::now()->format('Y-m-d'); // 2000-01-31

echo Date::now(); // 2000-01-31 12:00:00

echo $date->ago(); // 5 days ago

$date = new Date('+1000 days');
echo Date::now()->timespan($date);
// 2 years, 8 months, 3 weeks, 5 days

// or even
echo Date::now()->timespan('+1000 days');

$date = new Date('-10 years');
echo $date->age; // 10

$date = new Date('+10 years');
echo $date->age; // -10

$yesterday = Date::now()->sub('1 day');
$tomorrow  = Date::now()->add('1 day');

// ISO 8601
$date = Date::now()->add('P2Y4DT6H8M');

$date->year = 2013:
$date->month = 1;
$date->day = 31;

$date->hour = 12;
$date->minute = 0;
$date->second = 0;

'hour'      => '1 hour|:count hours',
'minute'    => '1 minute|:count minutes',
'second'    => '1 second|:count seconds',

'year'          => '1 Jahr|:count Jahre',
'year_ago'      => '1 Jahr|:count Jahren',
bash
php generator.php nl_NL