【发布时间】:2018-11-05 17:07:09
【问题描述】:
我正在使用 PHP DateTime 类为自定义许可系统生成日期。当我调试它时,我注意到日期时间总是错误的,它将是5-dec-2018,但现在我们是在 11 月,这个日期对于expiration_date 也将是相同的。
我该如何解决这个问题?我需要将试用期的开始日期增加 30 天。
这里是代码。
class Activator {
private $uuid;
private $keygen;
private $licence_code;
public static function generateLicence($uuid) {
if (!file_exists(ABSPATH.'/DataStorage/.licence')) {
$start_date = new DateTime();
$time_zone = $start_date->setTimezone(new DateTimeZone('Europe/Rome'));
$trial_date = $start_date->add(new DateInterval('P30D'));
$end_date = $trial_date->format('d-M-Y');
$machine_uuid = bin2hex($uuid);
$licence_code = base64_encode($machine_uuid);
$licence_file = array(
'uuid' => $machine_uuid,
'activation_date' => $time_zone->format('d-M-Y'),
#'trial_version' => true,
#'expire_date' => $end_date,
#'licence_code' => $licence_code
);
$w = file_put_contents(ABSPATH.'/DataStorage/.licence', json_encode($licence_file));
echo $w;
}
}
【问题讨论】: