meriksk / date-time
An international PHP extension for DateTime. Dt uses Carbon to manage date and time.
0.3
2024-06-04 14:48 UTC
Requires
- php: ^7.1.8 || ^8.0
- nesbot/carbon: ^3
Requires (Dev)
- phpunit/phpunit: ^10
README
An international PHP extension for DateTime. Dt uses Carbon to manage date and time. http://carbon.nesbot.com
Examples
<?php 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
Installation
With Composer
$ composer require meriksk/date-time
{ "require": { "meriksk/date-time": "*" } }
<?php require 'vendor/autoload.php'; use meriksk\DateTime\Dt; printf("Now: %s", Dt::now());