1. Go to this page and download the library: Download meriksk/date-time 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/ */
meriksk / date-time example snippets
use meriksk\DateTime\Dt;
// current time
printf("Right now is %s", Dt::now()->toDateTimeString());
printf("Right now in Vancouver is %s", Dt::now('America/Vancouver')); //implicit __toString()
// get format - it supports also aliases for date formats, i.e.: "date_time" is shortcut for "n/j/Y g:i:s A".
$format = Dt::getFormat('date'); // 'n/j/Y'
$format = Dt::getFormat('date_time'); // 'n/j/Y g:i:s A'
$format = Dt::getFormat('date_time_short'); // 'n/j/Y g:i A'
$format = Dt::getFormat('date_time_short', null, 'sk'); // 'j.n.Y H:i'
// convert format
$format = Dt::getFormat('date_time', Dt::TARGET_MOMENT); // D.M.YYYY HH:mm:ss
// get time
$dt = Dt::getTime('-1 week'); // Sub one week to the instance and resets the date to the first day of week
$dt = Dt::getTime('+1 month'); // Add one month to the instance with overflow explicitly forbidden and resets the date to the first day of month
// get boundaries
$b = Dt::getBoundaries('day', true); // boundaries for today
$b = Dt::getBoundaries('yesterday', true); // boundaries for yesterday
$b = Dt::getBoundaries('-2d', true); // day before yesterday
// resolve time
$b = Dt::resolveTime('now'); // current time
$b = Dt::resolveTime('now/d'); // the day so far (start of the day)
$b = Dt::resolveTime('now/d', true); // the day so far (end of the day)
$b = Dt::resolveTime('now-1w'); // previous week