简体   繁体   English

PHP中的日期戳功能

[英]Date stamp Function in php

I'm trying to make a subscription based system, once a person registers he/she can choose a package for 1/3/6 months and pay for it, once the payment is successful, a date stamp is added, this date stamp is based on the package ie if the package is purchased today it will be of the same day 3 months ahead or 1 month or whatever. 我正在尝试建立一个基于订阅的系统,一个人注册后,他/她就可以选择1/3/6个月的套餐并付款,一旦付款成功,便会添加一个日期戳,该日期戳是基于包装,即如果今天购买包装,它将是提前3个月或1个月之类的同一天。

I'm having problems creating a function that solves this. 我在创建可以解决此问题的功能时遇到了问题。

Let's say your package subscription is for 3 months from now. 假设您的套餐订购期为现在的3个月。 You can get that date like this: 您可以像这样获取日期:

echo date('Y-m-d H:i:s', strtotime('+3 months', time()));

This worked for me, thanks everyone! 这对我有用,谢谢大家!

$dateNow = new DateTime();
$dateAhead = $dateNow->add(DateInterval::createFromDateString('3 months'));
print $dateAhead->format('Y-m-d');
/**
 * @param $month your package subscription is for $month months from now
 * @param string $format
 * @return bool|string
 */
function subscription($month, $format = 'Y-m-d H:i:s')
{
    return date($format, strtotime('+' . $month . ' months', time()));
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM