- 优化时间门面,增加参数

v6 v6.0.99
Chaim 4 years ago
parent 127d4b02c2
commit e8c985a079

@ -1,3 +1,6 @@
## v6.0.98 / 2020-07-25
- 优化时间门面,增加参数
## v6.0.98 / 2020-07-25 ## v6.0.98 / 2020-07-25
- 优化时间门面 - 优化时间门面

@ -26,7 +26,7 @@ use think\db\exception\DbException;
/** /**
* 定义当前版本 * 定义当前版本
*/ */
const VERSION = '6.0.98'; const VERSION = '6.0.99';
if (!function_exists('get_ip_info')) { if (!function_exists('get_ip_info')) {
/** /**

@ -37,8 +37,8 @@ use think\Facade;
* @method static string getTimeDifference(string $end_time, string $start_time) 计算两个时间差 * @method static string getTimeDifference(string $end_time, string $start_time) 计算两个时间差
* @method static string dateToTimestamp(string $date) 将指定日期转换为时间戳 * @method static string dateToTimestamp(string $date) 将指定日期转换为时间戳
* @method static string timestampToDate(int $time, string $format = "Y-m-d H:i:s") 将指定时间戳转换为日期 * @method static string timestampToDate(int $time, string $format = "Y-m-d H:i:s") 将指定时间戳转换为日期
* @method static string dateRear(string $format = "Y-m-d H:i:s", int $mun = 10) 在当前时间之后的时间 * @method static string dateRear(string $format = "Y-m-d H:i:s", int $mun = 10, int $time) 在某个时间之前的时间
* @method static string dateBefore(string $format = "Y-m-d H:i:s", int $mun = 10) 在当前时间之前的时间 * @method static string dateBefore(string $format = "Y-m-d H:i:s", int $mun = 10, int $time) 在某个时间之后的时间
* @method static bool checkIsBetweenTime(string $start, string $end) 判断当前的时分是否在指定的时间段内 * @method static bool checkIsBetweenTime(string $start, string $end) 判断当前的时分是否在指定的时间段内
*/ */
class Times extends Facade class Times extends Facade

@ -99,27 +99,35 @@ class Times
} }
/** /**
* 在当前时间之前的时间 * 在某个时间之前的时间
* @param string $format 格式 * @param string $format 格式
* @param int $mun 多少秒 * @param int $mun 多少秒
* @param int $time
* @return false|string * @return false|string
*/ */
public function dateBefore(string $format = "Y-m-d H:i:s", int $mun = 60) public function dateBefore(string $format = "Y-m-d H:i:s", int $mun = 60, int $time = 0)
{ {
date_default_timezone_set('Asia/Shanghai'); date_default_timezone_set('Asia/Shanghai');
return date($format, time() - $mun); if (empty($time)) {
$time = time();
}
return date($format, $time - $mun);
} }
/** /**
* 在当前时间之后的时间 * 在某个时间之后的时间
* @param string $format 格式 * @param string $format 格式
* @param int $mun 多少秒 * @param int $mun 多少秒
* @param int $time
* @return false|string * @return false|string
*/ */
public function dateRear(string $format = "Y-m-d H:i:s", int $mun = 60) public function dateRear(string $format = "Y-m-d H:i:s", int $mun = 60, int $time = 0)
{ {
date_default_timezone_set('Asia/Shanghai'); date_default_timezone_set('Asia/Shanghai');
return date($format, time() + $mun); if (empty($time)) {
$time = time();
}
return date($format, $time + $mun);
} }

Loading…
Cancel
Save