coswat/grapes

简单的PHP日期和时间管理包

资助包维护!
coswat

v1.0.3 2023-06-21 19:09 UTC

This package is auto-updated.

Last update: 2024-09-22 00:20:19 UTC


README

php grapes 是一个强大且轻量级的日期和时间操作包,易于使用

composer require coswat/grapes

用法

use Coswat\Grapes\Grape;

$time = 169268267; //unix timestamp

//returns 05:38:22
Grape::time($time)->toTime();

//returns 2023-02-27 05:39:09
Grape::time($time)->toRaw();

//returns 2023
Grape::time($time)->toYear();

//returns February
Grape::time($time)->toMonth();

//returns Sunday
Grape::time($time)->toDay();

//returns 5 minutes ago 
Grape::time($time)->timeAgo();

//returns nextday timestamp or unix
Grape::time($time)->nextDay();

//returns nextweek timestamp and unix
Grape::time($time)->nextWeek();

//returns nextmonth timestamp and unix
Grape::time($time)->nextMonth(); 

//returns timestamp of custom dates, for adding day
Grape::time($time)->addDays(3,true);

//returns timestamp of custom dates, for adding weeks
Grape::time($time)->addWeeks(1);

//returns timestamp of custom dates, for adding months
Grape::time($time)->addMonths(3);

额外功能

$ip = '8.8.8.8'; //ip address 

Grape::getTimezone($ip); // returns Asia/Kolkata

$start_time = microtime(true);

 // code to run 
 
$end_time = microtime(true);

Grape::getMs($start_time,$end_time); //returns 0.42 ms

最新版本的新功能?

Grape::timeDiff(time(),1677625494);

/* will return time difference dynamically
(second,minutes,hours,days) */

Animated footer bars


Back to top