PHP code example of twipsi / chronos

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

    

twipsi / chronos example snippets


 Chronos::date(new Chronos)...
 Chronos::date(new DateTime)...
 Chronos::date('2022-05-05 10:10:10')...
 Chronos::date(1664524279)...

 new Chronos(new DateTime)
 

 Chronos::date()...
 

 Chronos::date($date)
    ->setDateTimeFormat("Y-m-d H:i:s")
    ->setDateFormat("Y-m-d")
    ->setTimeFormat("H:i:s")
    ->setTimezone("UTC")
 

 Chronos::date($date)...
     ->getDateObject()
     ->stamp()
     ->getDateTime()
     ->getDate()
     ->getTime()
     ->getHour()
     ->getMinute()
     ->getSeconds()
     ->getDayName()
     ->getDayShortName()
     ->getDayNumber()
     ->getWeekNumber()
     ->getMonthName()
     ->getShortMonthName()
     ->getMonthNumber()
     ->getYear()
 

 Chronos::date($date)->addDays()->getDateTime();
 Chronos::date($date)->addMinutes()->getDateTime();
 Chronos::date($date)->addSeconds()->getDateTime();
 Chronos::date($date)->subDays()->getDateTime();
 Chronos::date($date)->subMinutes()->getDateTime();
 Chronos::date($date)->subSeconds()->getDateTime();
 

 Chronos::date($date)->addDays(40)->addMinutes(1)->subSeconds(20)->getDateTime();
 

 Chronos::date()->travel(new DateTime)...
 Chronos::date()->travel('2022-05-05 10:10:10')...
 Chronos::date()->travel(1664524279)...
 

 Chronos::date()->travel('2022-05-05 10:10:10')
     ->daysPassed() // This will return 0 if travel date is in the future.
     ->differenceInDays() // This will return negative days if travel is in the past.
     ->hoursPassed()
     ->differenceInHours()
     ->minutesPassed()
     ->differenceInMinutes()
     ->secondsPassed()
     ->differenceInSeconds()
 

 Chronos::date()->travel('2022-05-05 10:10:10')
     ->isInFuture()
     ->isInPast()