meriksk / date-time
An international PHP extension for DateTime. Dt uses Carbon to manage date and time.
0.2
2022-08-09 10:43 UTC
Requires
- php: ^7.1.8 || ^8.0
- nesbot/carbon: ^2.0
Requires (Dev)
- phpunit/phpunit: ^9.5
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('-1 day', true); // boundaries for yestarday
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());